1

私はRichtextBoxMenustripおよびその他の多くのコントロールを使用する 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
}
4

4 に答える 4

3

エンターキーを押すたびにあなたの行を表示します。コードは以下のとおりです:::----

private void Key_Down(object sender, KeyEventArgs e)
{
    if (e.KeyData == Keys.Enter)
    {
        int line = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart);
        int column = richTextBox1.SelectionStart - richTextBox1.GetFirstCharIndexFromLine(line);

        toolStripStatusLabel5.Text = "Line" + " " + line.ToString();
        toolStripStatusLabel6.Text = " Column" + " " + column.ToString();
        toolStripStatusLabel3.Text = Cursor.Position.ToString(); // where is my mouse cursor at this Time like that x and y cordinate 330,334
        Update();
    }
}
于 2013-02-28T23:10:29.847 に答える
1

私はStackoverFlowと甘いユーザー(プログラマー)の助けを借りてやりました。返信ありがとうございます。私のコードは

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();

        }

    }
于 2013-02-28T23:03:45.193 に答える
1

イベントをサブスクライブして、現在のマウス位置でラベルRichTextBox MouseMoveを更新できますToolStrip

例:

private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
{
    toolStripStatusLabel3.Text = string.Format("X={0}, Y={1}", e.X, e.Y);
}

または、 に関連する位置を表示する場合は、からRichTextBoxを使用できます。これにより、 (テキストボックスの左上 = 0,0)内の位置が返されます。LocationMouseEventArgsRichTextBox

private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
{
    toolStripStatusLabel3.Text = string.Format("X={0}, Y={1}", e.Location.X, e.Location.Y);
}
于 2013-02-28T22:19:59.297 に答える
1

位置を自動的に更新したい場合は、代わりに richtextbox の MouseMove イベントを使用する必要があります。マウスを動かしている間、常に更新されています。また、MouseMove 呼び出しの「MouseEventArgs e」は、リッチテキスト ボックス内のカーソル位置を示します。

于 2013-02-28T22:21:41.873 に答える