Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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.
Posted
Comments
Sergey Alexandrovich Kryukov 11-May-11 0:32am    
Alt-Spacebar should remain the window's icon menu (system menu), nothing else.
--SA

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.

C#
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);
           }
       }
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 11-May-11 23:02pm    
No need in P/Invoke.

Please see my answer.
--SA
CS2011 12-May-11 0:52am    
Did not know that. Thanks :-) 5+
If you're using System.Windows.Forms.RichTextBox, this is how to find the coordinates:

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


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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900