如何在Richtext中获取光标的位置 [英] How to get the location of cursor in Richtext

查看:75
本文介绍了如何在Richtext中获取光标的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的大家,
我是编程的初学者.
当我学习了如何使用VS.net进行C#编程时,我发现当按Atl +空格键时,在RTF文本光标处会出现一个迷你菜单(不确切知道它的名称).
如果我将光标移到另一行并再次按下组合的按钮(Atl + Spacebar),它将出现在文本光标处.我试图做到这一点.但是绝望.也许我太糟糕了.有人对我有个好主意吗?
我将很高兴向我展示如何制作.
我只想知道如何使它像这样运行.
这样我就可以在程序中使用它了.
先生,因为我的英语不好.
阅读感谢.
您诚挚的.

Dear Everyone,
I am beginner in programming.
When i learned how to programming C# with VS.net, i saw that a mini menu( don''t know exactly it''s name)appears at the text cursor in richtext when i press Atl+Spacebar.
And if i move the cusrsor to another line and press that combined buttons(Atl+Spacebar)again,it''ll appear at the text cursor. I tried to do that. But hopeless.Maybe i am too bad.Have anyone have a good idea???
I will grateful for showing me how to make it.
I just want to know how to make it run like that.
So that i can use it in my program.
Sr for my bad English.
Thx for reading.
Your sincerely.

推荐答案

首先,该菜单称为上下文菜单.第二个ALT + SPACE由操作系统处理,我建议使用其他一些按键组合,但是,如果您仍然想执行相同的简单方法,就是将窗体的控件框属性设置为False.

First of all the menu is called context menu. Second ALT+SPACE is handled by OS i would suggest to use some other key combination however if you still want to do the same easy way is to set control box property of the form to False.

public partial class Form1 : Form
   {
       [DllImport("user32.dll")]
       [return: MarshalAs(UnmanagedType.Bool)]
       static extern bool GetCaretPos(out Point lpPoint);

       public Form1()
       {
           InitializeComponent();
       }
       private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
       {
           //if ((rtb1.Mo & Keys.Shift) == Keys.Shift)
           //{
           //}
       }
       private void rtb1_KeyDown(object sender, KeyEventArgs e)
       {
           Point p= new Point();
           //This will display the context menu when you press ctrl+Shift key
           if (e.Shift && e.Control)
            // you can use following condition if you have set the control box property to false
            //if (e.Alt && e.KeyCode == Keys.Space)
           {
               //MessageBox.Show("Control+shift");
               GetCaretPos(out p);
               cmenu.Show(rtb1, p);
           }
       }


如果您使用的是System.Windows.Forms.RichTextBox,这是查找坐标的方法:

If you''re using System.Windows.Forms.RichTextBox, this is how to find the coordinates:

System.Drawing.Point whereIsTheCursor =
   myRichTextBox.GetPositionFromCharIndex(
      myRichTextBox.SelectionStart);



请记住,Alt +空格键应弹出窗口的系统菜单(在窗口的图标处);因此您不想破坏这种重要的按键组合.

—SA



Please remember that Alt+spacebar should popup the window''s system menu (at the window''s icon); so you don''t want to disrupt this important key combination.

—SA


这篇关于如何在Richtext中获取光标的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆