[DllImport("user32")]
public static extern bool GetCaretPos(ref System.Drawing.Point lpPoint);
定义X Y
private int X = 0;
private int Y = 0;
方法自己定义把下面这段放进去
Point P = new Point(0);
GetCaretPos(ref P);
int Pos = this.richTextBox1.GetCharIndexFromPosition(P);
this.Y = this.richTextBox1.GetLineFromCharIndex(Pos);
if (this.Y > 0)
{
int offset = 1;
while (this.richTextBox1.Text[Pos - offset] != '\n')
offset++;
this.X = offset;
this.Y++;
}
else
{
this.X = Pos + 1;
this.Y = 1;
}
MessageBox.Show("当前位置: 第" + this.Y.ToString() + "行 " + "第" + this.X.ToString() + "列");
public static extern bool GetCaretPos(ref System.Drawing.Point lpPoint);
定义X Y
private int X = 0;
private int Y = 0;
方法自己定义把下面这段放进去
Point P = new Point(0);
GetCaretPos(ref P);
int Pos = this.richTextBox1.GetCharIndexFromPosition(P);
this.Y = this.richTextBox1.GetLineFromCharIndex(Pos);
if (this.Y > 0)
{
int offset = 1;
while (this.richTextBox1.Text[Pos - offset] != '\n')
offset++;
this.X = offset;
this.Y++;
}
else
{
this.X = Pos + 1;
this.Y = 1;
}
MessageBox.Show("当前位置: 第" + this.Y.ToString() + "行 " + "第" + this.X.ToString() + "列");