private void button2_Click(object sender, EventArgs e)
{
Win32CommonDialog.frm_GOTO frm = new Win32CommonDialog.frm_GOTO();
frm.label1.Text = "等号(1 - " + richTextBox1.Lines.Length.ToString() + ")(&L)";
int L = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart);
frm.textBox1.Text = L.ToString();
if (frm.ShowDialog() == DialogResult.OK)
{
int Line = Convert.ToInt32(frm.textBox1.Text);
if ( Line >= 1 ){
if (Line > richTextBox1.Lines.Length)
{
MessageBox.Show("行数大于现有的行数");
}
else
{
richTextBox1.SelectionStart = richTextBox1.GetFirstCharIndexFromLine(Line - 1);
richTextBox1.SelectionLength = 0;
richTextBox1.Focus();
richTextBox1.ScrollToCaret();
}
}
}
转到行号
private void button2_Click(object sender, EventArgs e)
{
int Line = Convert.ToInt32(
Microsoft.VisualBasic.Interaction.InputBox("行号", "转到行", "0", -1, -1)
);
if (Line > richTextBox1.Lines.Length)
{
MessageBox.Show("行数大于现有的行数");
}
else
{
richTextBox1.SelectionStart = richTextBox1.GetFirstCharIndexFromLine(Line - 1);
richTextBox1.SelectionLength = 0;
richTextBox1.Focus();
richTextBox1.ScrollToCaret();
}
}
//获得当前的行号
private void richTextBox1_SelectionChanged(object sender, EventArgs e)
{
Text = richTextBox1.SelectionStart.ToString();
int pos = richTextBox1.SelectionStart;
int x = richTextBox1.GetLineFromCharIndex(pos) +1; //行
int y = pos - (richTextBox1.GetFirstCharIndexFromLine(richTextBox1.GetLineFromCharIndex(pos) - 1) + 1 ) + 1; //列
Text = x.ToString() +" " + y.ToString();
}