C#窗体程序 如何在光标处插入指定文本。
C#窗体程序如何在光标处插入指定文本,光标可能脱离程序窗体本身,光标可能在其他程序里如其他网页文本框里。谁能给个代码?或者给点提示谢谢...
C#窗体程序 如何在光标处插入指定文本,光标可能脱离程序窗体本身,光标可能在其他程序里 如其他网页文本框里。谁能给个代码?或者给点提示 谢谢
展开
5个回答
展开全部
告诉你一个简单的处理方法,
首先把你要插入的文本通过代码放到剪切板里,
然后再通过代码发送ctrl+V命令,
这样不管光标在哪都可以插入文本的
首先把你要插入的文本通过代码放到剪切板里,
然后再通过代码发送ctrl+V命令,
这样不管光标在哪都可以插入文本的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-06-19
展开全部
你用的是这种方式吧?
textBox1.Text += "123";
这样就可以了:
textBox1.SelectionText = "123";
“文本框中光标移动时触发的什么事件?”
没有这个事件
textBox1.Text += "123";
这样就可以了:
textBox1.SelectionText = "123";
“文本框中光标移动时触发的什么事件?”
没有这个事件
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/// 在当前光标位置插入内容
/// </summary>
/// <param name="text">内容</param>
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;
}
/// </summary>
/// <param name="text">内容</param>
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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-06-18
展开全部
Clipboard.SetText("XXXXXXXX"); //把要插入的文本放到剪切板
SendKeys.Send("^v"); // 模拟ctrl+v
SendKeys.Send("^v"); // 模拟ctrl+v
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询