我想從我的C#Winforms應用程序中將一些行從MS Excel複製並粘貼到richTextBox。用戶將在鍵盤上按下CTRL + V並顯示Excel網格線。 ?可我怎麼確保粘貼的內容將只顯示爲文本#在富文本框中刪除電子表格格式
這似乎並不工作:
private void button1_Click(object sender, EventArgs e)
{
richTextBox2.Clear();
richTextBox2.Focus();
string strValues;
strValues = richTextBox1.Text;
var textInEachLine = richTextBox1.Text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string whereClause = string.Join("', '", textInEachLine).ToString();
richTextBox2.AppendText(" IN ('" + whereClause + "')");
}
:
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control == true && e.KeyCode == Keys.V)
{
e.Handled = true;
string st = Clipboard.GetText();
richTextBox1.Text = st;
}
}
爲我的代碼看起來是這樣的,我不能用一個文本框
一個解決方案可能是使用'textbox'並將'multiline'選項設置爲true而不是'richtextbox' – Marek
用我的代碼更新了我的問題。我無法使用文本框,因爲我使用的是字符串數組。除非你可以重寫它並告訴我 – PriceCheaperton
對於我來說你提供的代碼正在工作,這個問題一定在別的地方。這個'richtextbox'上還有更多事件嗎? – Marek