C#窗体程序 如何在光标处插入指定文本。
答案:5 悬赏:80 手机版
解决时间 2021-04-02 06:41
- 提问者网友:沦陷
- 2021-04-01 19:38
C#窗体程序 如何在光标处插入指定文本。
最佳答案
- 五星知识达人网友:酒醒三更
- 2021-04-01 20:56
有一个简单的处理方法,首先把你要插入的文本通过代码放到剪切板里,然后再通过代码发送ctrl+V命令,这样不管光标在哪都可以插入文本的
Clipboard.SetText("小花朵"); //把要插入的文本放到剪切板
SendKeys.Send("^v"); // 模拟ctrl+v
Clipboard.SetText("小花朵"); //把要插入的文本放到剪切板
SendKeys.Send("^v"); // 模拟ctrl+v
全部回答
- 1楼网友:青灯有味
- 2021-04-02 00:12
告诉你一个简单的处理方法,
首先把你要插入的文本通过代码放到剪切板里,
然后再通过代码发送ctrl+V命令,
这样不管光标在哪都可以插入文本的
首先把你要插入的文本通过代码放到剪切板里,
然后再通过代码发送ctrl+V命令,
这样不管光标在哪都可以插入文本的
- 2楼网友:躲不过心动
- 2021-04-01 23:05
/// 在当前光标位置插入内容
///
/// 内容
public void SelectionInsertText(string text)
{
Word.Selection currentSelection = Application.Selection;
// Store the user's current Overtype selection
bool userOvertype = Application.Options.Overtype;
// Make sure Overtype is turned off.
if (Application.Options.Overtype)
{
Application.Options.Overtype = false;
}
// Test to see if selection is an insertion point.
if (currentSelection.Type == Word.WdSelectionType.wdSelectionIP)
{
//currentSelection.TypeText("Inserting at insertion point. ");
currentSelection.TypeText(text);
currentSelection.TypeParagraph();
}
else
{
if (currentSelection.Type == Word.WdSelectionType.wdSelectionNormal)
{
// Move to start of selection.
if (Application.Options.ReplaceSelection)
{
object direction = Word.WdCollapseDirection.wdCollapseStart;
currentSelection.Collapse(ref direction);
}
//currentSelection.TypeText("Inserting before a text block. ");
currentSelection.TypeText(text);
currentSelection.TypeParagraph();
}
else
{
// Do nothing.
}
}
// Restore the user's Overtype selection
Application.Options.Overtype = userOvertype;
}
///
/// 内容
public void SelectionInsertText(string text)
{
Word.Selection currentSelection = Application.Selection;
// Store the user's current Overtype selection
bool userOvertype = Application.Options.Overtype;
// Make sure Overtype is turned off.
if (Application.Options.Overtype)
{
Application.Options.Overtype = false;
}
// Test to see if selection is an insertion point.
if (currentSelection.Type == Word.WdSelectionType.wdSelectionIP)
{
//currentSelection.TypeText("Inserting at insertion point. ");
currentSelection.TypeText(text);
currentSelection.TypeParagraph();
}
else
{
if (currentSelection.Type == Word.WdSelectionType.wdSelectionNormal)
{
// Move to start of selection.
if (Application.Options.ReplaceSelection)
{
object direction = Word.WdCollapseDirection.wdCollapseStart;
currentSelection.Collapse(ref direction);
}
//currentSelection.TypeText("Inserting before a text block. ");
currentSelection.TypeText(text);
currentSelection.TypeParagraph();
}
else
{
// Do nothing.
}
}
// Restore the user's Overtype selection
Application.Options.Overtype = userOvertype;
}
- 3楼网友:不想翻身的咸鱼
- 2021-04-01 21:47
Clipboard.SetText("XXXXXXXX"); //把要插入的文本放到剪切板
SendKeys.Send("^v"); // 模拟ctrl+v
SendKeys.Send("^v"); // 模拟ctrl+v
- 4楼网友:枭雄戏美人
- 2021-04-01 21:23
你用的是这种方式吧?
textBox1.Text += "123";
这样就可以了:
textBox1.SelectionText = "123";
“文本框中光标移动时触发的什么事件?”
没有这个事件
textBox1.Text += "123";
这样就可以了:
textBox1.SelectionText = "123";
“文本框中光标移动时触发的什么事件?”
没有这个事件
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯