如何使用Windows窗体将光标指向文本框的特定行 [英] How to point the cursor on the particular line of a textbox using Windows forms
问题描述
我有两种形式,即Form1和Form2;
我想转到Form1文本框中的特定行说第3行。
光标应指向特定行的开头。
输入在其他表格的文本框中给出。
它在记事本中的Goto函数
I am having two forms namely Form1 and Form2;
I want to goto a particular line in the text box of Form1 say line 3.
Cursor should be pointed on the beginning of the particular line.
Input is given on the textbox of other form.
Its Goto function in Notepad
推荐答案
根据我的理解,你想将光标的位置设置在
a TextBox中,就在第一个字符之前文本。
Based on my understanding, you'd like to set the position of the cursor in
a TextBox to just before the first character of the text.
以下是示例代码。它要求你在
表格上添加一个TextBox。
The following is a sample code. It requires that you add a TextBox on a
form.
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.Text = "hell world text testing cursor pointer ...";
this.textBox1.SelectionStart = 0;
}
或
检查
具有搜索行编号,项目符号,打印,搜索支持的RichTextBox [ ^ ]
问候,
Praveen Nelge
or
Check it
RichTextBox with Search Line Numbering, Bulleting, Printing, Searching Support[^]
Regards,
Praveen Nelge
int position = 0;
public void GotoLine(int LineNum) // Go to line num...
{
position = 0;
for (int i = 1; i <= LineNum; i++)
FindNext("\n");
}
public void FindNext(string FindValue) // Find word...
{
int start = this.TextBox1.Text.IndexOf(FindValue, position);
int length = FindValue.Length;
this.TextBox1.Select(start, length);
position = start + length;
}
-KR
-KR
这篇关于如何使用Windows窗体将光标指向文本框的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!