C# 是否将当前光标位置显示为当前行和当前列?

C# 是否将当前光标位置显示为当前行和当前列?,c#,winforms,cursor,C#,Winforms,Cursor,我正在开发使用RichtextBox、Menustrip和更多控件的Windows窗体应用程序 我做了一些工作,但没能把它付诸实施。当我的鼠标光标在RichTextBox中移动时,我想自动改变位置,就像简单记事本上那样 我的位编码是 我想要它,因此当我的鼠标光标移动时,它会更改状态栏上的动态位置 private void sizeToolStripMenuItem_Click(object sender, EventArgs e) { int line = richTex

我正在开发使用
RichtextBox
Menustrip
和更多控件的Windows窗体应用程序

我做了一些工作,但没能把它付诸实施。当我的鼠标光标在RichTextBox中移动时,我想自动改变位置,就像简单记事本上那样

我的位编码是

我想要它,因此当我的鼠标光标移动时,它会更改状态栏上的动态位置

private void sizeToolStripMenuItem_Click(object sender, EventArgs e)
{        
    int line = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart);
    int column = richTextBox1.SelectionStart - richTextBox1.GetFirstCharIndexFromLine(line);
    toolStripStatusLabel5.Text ="Line"+" "+ line.ToString();
    toolStripStatusLabel6.Text = " Column" + " " + line.ToString();
    toolStripStatusLabel3.Text= Cursor.Position.ToString(); // where is my mouse cursor at this Time like that x and y cordinate 330,334
}

您可以订阅
RichTextBox
MouseMove
事件,用当前鼠标位置更新
ToolStrip
标签

例如:

private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
{
    toolStripStatusLabel3.Text = string.Format("X={0}, Y={1}", e.X, e.Y);
}
或者,如果您希望它显示与
RichTextBox
相关的位置,您可以使用
MouseEventArgs
中的
位置,这将返回
RichTextBox
中的位置(textbox的左上角=0,0)


您可以订阅
RichTextBox
MouseMove
事件,用当前鼠标位置更新
ToolStrip
标签

例如:

private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
{
    toolStripStatusLabel3.Text = string.Format("X={0}, Y={1}", e.X, e.Y);
}
或者,如果您希望它显示与
RichTextBox
相关的位置,您可以使用
MouseEventArgs
中的
位置,这将返回
RichTextBox
中的位置(textbox的左上角=0,0)


如果您想自动更新位置,应该使用richtextbox中的MouseMove事件。当你移动鼠标时,它总是在更新。另外,MouseMove调用中的“MouseEventArgs e”可以为您提供richtextbox中的光标位置。

如果您想自动更新位置,应该使用richtextbox中的MouseMove事件。当你移动鼠标时,它总是在更新。另外,MouseMove调用中的“MouseEventArgs e”可以为您提供richtextbox中的光标位置。

我在StackoverFlow和sweetly user(程序员)的帮助下完成了这项工作。 谢谢你的回复。我的代码是

private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
    {

        if (e.Button == MouseButtons.Left)
        {
            int line = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart);
            int column = richTextBox1.SelectionStart - richTextBox1.GetFirstCharIndexFromLine(line);

            toolStripStatusLabel5.Text = "Line" + " " + line.ToString();
            toolStripStatusLabel6.Text = " Column" + " " + line.ToString();
            toolStripStatusLabel3.Text = Cursor.Position.ToString(); // where is my mouse cursor at this Time like that x and y cordinate 330,334
            Update();

        }

    }

我在StackoverFlow和sweetly用户(程序员)的帮助下完成了这项工作。 谢谢你的回复。我的代码是

private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
    {

        if (e.Button == MouseButtons.Left)
        {
            int line = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart);
            int column = richTextBox1.SelectionStart - richTextBox1.GetFirstCharIndexFromLine(line);

            toolStripStatusLabel5.Text = "Line" + " " + line.ToString();
            toolStripStatusLabel6.Text = " Column" + " " + line.ToString();
            toolStripStatusLabel3.Text = Cursor.Position.ToString(); // where is my mouse cursor at this Time like that x and y cordinate 330,334
            Update();

        }

    }

每次按enter键时显示您的行。 代码如下所示:----


每次按enter键时显示您的行。 代码如下所示:----


你能分享一下MouseMove编码吗?你能分享一下MouseMove编码吗