【发布时间】:2018-01-11 23:00:38
【问题描述】:
我想将一些行从 MS Excel 复制并粘贴到我的 C# Winforms 应用程序中的 RichTextBox。用户将按键盘上的 CTRL+V 并显示 Excel 网格线。如何确保粘贴的内容仅显示为文本?#
这似乎不起作用:
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;
}
}
我无法使用文本框,因为我的代码如下所示:
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 + "')");
}
【问题讨论】:
-
一种解决方案可能是使用
textbox并将multiline选项设置为true 而不是richtextbox -
用我的代码更新了我的问题。我不能使用文本框,因为我使用的是字符串数组。除非你能改写给我看
-
对我来说,您提供的代码正在运行,问题一定出在其他地方。这个
richtextbox还有更多活动吗? -
当您说它的工作时,您是否从 Excel 中复制了单元格并尝试粘贴它?如果您看到网格线,则说明它不起作用...
-
相信我,我没有看到任何网格线。所以这个 Richtextbox 上没有更多事件了吧?