Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Repositioning the cursor

Repositioning the cursor

Scheduled Pinned Locked Moved C#
tutorialcomhelp
15 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skhan17
    wrote on last edited by
    #1

    Hello, I am looking for ways to reposition the cursor when I am clicked on the first menu item from a form menu. It should create a jumping effect so the user doesn't have to scroll through the other menus which don't have a child menu. for example.... one file menu has 4 items. Namely 1, 2, 3, 4 now only item 2 has child menu items. namely 2.1, 2.2, 2.3. I want the cursor to be on 2.1 when the user brings the mouse on 2. Please let me know how to do that. I am trying the following:

    private void toolStripMenuItem2_MouseHover(object sender, EventArgs e)
    {
    toolStripMenuItem2.ShowDropDown();
    Point LocalMousePosition_1 = this.PointToClient(Cursor.Position);
    System.Windows.Forms.Cursor.Position = new Point(500, 500); //This just repositions the cursor to 500,500 position but not in the net child menu. This is where I am stuck.

            //Point LocalMousePosition\_2 = toolStripMenuItem2\_1.PointToClient(Cursor.Position);
            MessageBox.Show(LocalMousePosition\_1+"Happy New Year to DOTNETSPIDER.COM guys");        
        }
    
    P S A S 4 Replies Last reply
    0
    • S skhan17

      Hello, I am looking for ways to reposition the cursor when I am clicked on the first menu item from a form menu. It should create a jumping effect so the user doesn't have to scroll through the other menus which don't have a child menu. for example.... one file menu has 4 items. Namely 1, 2, 3, 4 now only item 2 has child menu items. namely 2.1, 2.2, 2.3. I want the cursor to be on 2.1 when the user brings the mouse on 2. Please let me know how to do that. I am trying the following:

      private void toolStripMenuItem2_MouseHover(object sender, EventArgs e)
      {
      toolStripMenuItem2.ShowDropDown();
      Point LocalMousePosition_1 = this.PointToClient(Cursor.Position);
      System.Windows.Forms.Cursor.Position = new Point(500, 500); //This just repositions the cursor to 500,500 position but not in the net child menu. This is where I am stuck.

              //Point LocalMousePosition\_2 = toolStripMenuItem2\_1.PointToClient(Cursor.Position);
              MessageBox.Show(LocalMousePosition\_1+"Happy New Year to DOTNETSPIDER.COM guys");        
          }
      
      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      That sounds user-hostile -- I wouldn't use your application if it did that.

      1 Reply Last reply
      0
      • S skhan17

        Hello, I am looking for ways to reposition the cursor when I am clicked on the first menu item from a form menu. It should create a jumping effect so the user doesn't have to scroll through the other menus which don't have a child menu. for example.... one file menu has 4 items. Namely 1, 2, 3, 4 now only item 2 has child menu items. namely 2.1, 2.2, 2.3. I want the cursor to be on 2.1 when the user brings the mouse on 2. Please let me know how to do that. I am trying the following:

        private void toolStripMenuItem2_MouseHover(object sender, EventArgs e)
        {
        toolStripMenuItem2.ShowDropDown();
        Point LocalMousePosition_1 = this.PointToClient(Cursor.Position);
        System.Windows.Forms.Cursor.Position = new Point(500, 500); //This just repositions the cursor to 500,500 position but not in the net child menu. This is where I am stuck.

                //Point LocalMousePosition\_2 = toolStripMenuItem2\_1.PointToClient(Cursor.Position);
                MessageBox.Show(LocalMousePosition\_1+"Happy New Year to DOTNETSPIDER.COM guys");        
            }
        
        S Offline
        S Offline
        skhan17
        wrote on last edited by
        #3

        It doesn't matter if it's hostile or not, I need it now for some reason... let's just say all the supervisors in the MSc. program are crazy...... if you know a solution please help me ...otherwise please mind your own business....

        P P 2 Replies Last reply
        0
        • S skhan17

          It doesn't matter if it's hostile or not, I need it now for some reason... let's just say all the supervisors in the MSc. program are crazy...... if you know a solution please help me ...otherwise please mind your own business....

          P Offline
          P Offline
          Paw Jershauge
          wrote on last edited by
          #4

          Easy now skhan17, no need to get all personal and stuff... hi just posted his opinion... But here try this: System.Windows.Forms.Cursor.Position = [MenuItem2.1].PointToClient(); One thing here to remember is, that you CANNOT call this before the [MenuItem2.1] has been shown. ;) Hope it works

          With great code, comes great complexity, so keep it simple stupid...:-\ :-\

          S 1 Reply Last reply
          0
          • P Paw Jershauge

            Easy now skhan17, no need to get all personal and stuff... hi just posted his opinion... But here try this: System.Windows.Forms.Cursor.Position = [MenuItem2.1].PointToClient(); One thing here to remember is, that you CANNOT call this before the [MenuItem2.1] has been shown. ;) Hope it works

            With great code, comes great complexity, so keep it simple stupid...:-\ :-\

            S Offline
            S Offline
            skhan17
            wrote on last edited by
            #5

            well it doesn't let me add that... i have tried that... it says : Error 1 'System.Windows.Forms.ToolStripMenuItem' does not contain a definition for 'PointToClient' and no extension method 'PointToClient' accepting a first argument of type 'System.Windows.Forms.ToolStripMenuItem' could be found (are you missing a using directive or an assembly reference?) I am sure that the child menu item has been shown before that.... please help.... Thanks for replying......

            P 1 Reply Last reply
            0
            • S skhan17

              well it doesn't let me add that... i have tried that... it says : Error 1 'System.Windows.Forms.ToolStripMenuItem' does not contain a definition for 'PointToClient' and no extension method 'PointToClient' accepting a first argument of type 'System.Windows.Forms.ToolStripMenuItem' could be found (are you missing a using directive or an assembly reference?) I am sure that the child menu item has been shown before that.... please help.... Thanks for replying......

              P Offline
              P Offline
              Paw Jershauge
              wrote on last edited by
              #6

              Ohhh my god, what was i thinking, ofcause you cannot do that... sorry m8. Let me get back to you in a moment...

              With great code, comes great complexity, so keep it simple stupid...:-\ :-\

              P 1 Reply Last reply
              0
              • P Paw Jershauge

                Ohhh my god, what was i thinking, ofcause you cannot do that... sorry m8. Let me get back to you in a moment...

                With great code, comes great complexity, so keep it simple stupid...:-\ :-\

                P Offline
                P Offline
                Paw Jershauge
                wrote on last edited by
                #7

                Well i couldnt really find anything for you mate, sorry. But try look for HitTest methods or perhaps you shall loop through all MenuItems to do some calculation of somesort... Sorry i couldnt be of more help... :doh: :doh: :doh:

                With great code, comes great complexity, so keep it simple stupid...:-\ :-\

                1 Reply Last reply
                0
                • S skhan17

                  It doesn't matter if it's hostile or not, I need it now for some reason... let's just say all the supervisors in the MSc. program are crazy...... if you know a solution please help me ...otherwise please mind your own business....

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  skhan17 wrote:

                  all the supervisors in the MSc. program are crazy

                  I can imagine. I have no idea, but will Focus have any effect?

                  S 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    skhan17 wrote:

                    all the supervisors in the MSc. program are crazy

                    I can imagine. I have no idea, but will Focus have any effect?

                    S Offline
                    S Offline
                    skhan17
                    wrote on last edited by
                    #9

                    I don't know how to use focus.....can you please let me know how to use mouse focus... then I can use it..maybe

                    1 Reply Last reply
                    0
                    • S skhan17

                      Hello, I am looking for ways to reposition the cursor when I am clicked on the first menu item from a form menu. It should create a jumping effect so the user doesn't have to scroll through the other menus which don't have a child menu. for example.... one file menu has 4 items. Namely 1, 2, 3, 4 now only item 2 has child menu items. namely 2.1, 2.2, 2.3. I want the cursor to be on 2.1 when the user brings the mouse on 2. Please let me know how to do that. I am trying the following:

                      private void toolStripMenuItem2_MouseHover(object sender, EventArgs e)
                      {
                      toolStripMenuItem2.ShowDropDown();
                      Point LocalMousePosition_1 = this.PointToClient(Cursor.Position);
                      System.Windows.Forms.Cursor.Position = new Point(500, 500); //This just repositions the cursor to 500,500 position but not in the net child menu. This is where I am stuck.

                              //Point LocalMousePosition\_2 = toolStripMenuItem2\_1.PointToClient(Cursor.Position);
                              MessageBox.Show(LocalMousePosition\_1+"Happy New Year to DOTNETSPIDER.COM guys");        
                          }
                      
                      A Offline
                      A Offline
                      Alan N
                      wrote on last edited by
                      #10

                      Hi, Handle the DropDownOpening or DropDownOpened event that occurs when your child menu appears. The Location property will get the screen coordinates of the top left corner of the menu. Apply an offset to put the cursor into the centre of the first menu item.

                      private void MenuItem_DropDownOpening(object sender, EventArgs e) {
                      ToolStripMenuItem menu = (ToolStripMenuItem)sender;

                      Point p = menu.DropDown.Location; // screen coords
                      Rectangle r = menu.DropDown.Items[0].Bounds;
                      p.Offset(r.Width / 2, r.Height / 2);
                      Cursor.Position = p;
                      }

                      Alan.

                      S 1 Reply Last reply
                      0
                      • A Alan N

                        Hi, Handle the DropDownOpening or DropDownOpened event that occurs when your child menu appears. The Location property will get the screen coordinates of the top left corner of the menu. Apply an offset to put the cursor into the centre of the first menu item.

                        private void MenuItem_DropDownOpening(object sender, EventArgs e) {
                        ToolStripMenuItem menu = (ToolStripMenuItem)sender;

                        Point p = menu.DropDown.Location; // screen coords
                        Rectangle r = menu.DropDown.Items[0].Bounds;
                        p.Offset(r.Width / 2, r.Height / 2);
                        Cursor.Position = p;
                        }

                        Alan.

                        S Offline
                        S Offline
                        skhan17
                        wrote on last edited by
                        #11

                        THANK YOU SO MUCH..... although I have figured out a manual way.... but this works like a charm....

                        1 Reply Last reply
                        0
                        • S skhan17

                          Hello, I am looking for ways to reposition the cursor when I am clicked on the first menu item from a form menu. It should create a jumping effect so the user doesn't have to scroll through the other menus which don't have a child menu. for example.... one file menu has 4 items. Namely 1, 2, 3, 4 now only item 2 has child menu items. namely 2.1, 2.2, 2.3. I want the cursor to be on 2.1 when the user brings the mouse on 2. Please let me know how to do that. I am trying the following:

                          private void toolStripMenuItem2_MouseHover(object sender, EventArgs e)
                          {
                          toolStripMenuItem2.ShowDropDown();
                          Point LocalMousePosition_1 = this.PointToClient(Cursor.Position);
                          System.Windows.Forms.Cursor.Position = new Point(500, 500); //This just repositions the cursor to 500,500 position but not in the net child menu. This is where I am stuck.

                                  //Point LocalMousePosition\_2 = toolStripMenuItem2\_1.PointToClient(Cursor.Position);
                                  MessageBox.Show(LocalMousePosition\_1+"Happy New Year to DOTNETSPIDER.COM guys");        
                              }
                          
                          S Offline
                          S Offline
                          Som Shekhar
                          wrote on last edited by
                          #12

                          PIEBALDconsult wrote:

                          That sounds user-hostile

                          Agree completely... Tell me something, how will you go to menu no 3? when you are moving your mouse down to item 1, and then to item 2, and boom... your mouse has gone to item 2.1 :D HORRIBLE

                          S 1 Reply Last reply
                          0
                          • S Som Shekhar

                            PIEBALDconsult wrote:

                            That sounds user-hostile

                            Agree completely... Tell me something, how will you go to menu no 3? when you are moving your mouse down to item 1, and then to item 2, and boom... your mouse has gone to item 2.1 :D HORRIBLE

                            S Offline
                            S Offline
                            skhan17
                            wrote on last edited by
                            #13

                            I agree with you too...it's horrible.... and since we both agree on this issue, there is a little chance that you'll also agree that some people always see the glass as half empty...... I chose not to be one of them. Finally thank you Alan N for helping me out.

                            S 1 Reply Last reply
                            0
                            • S skhan17

                              I agree with you too...it's horrible.... and since we both agree on this issue, there is a little chance that you'll also agree that some people always see the glass as half empty...... I chose not to be one of them. Finally thank you Alan N for helping me out.

                              S Offline
                              S Offline
                              Som Shekhar
                              wrote on last edited by
                              #14

                              Dude!! I am not seeing the glass as half empty buddy... There is a fine line between optimism and hallucination. I am always there standing next to you on optimism and I would always prefer to see the glass as half full... I only reasoned my doubt that how would you go to Menu Item number 3 in your example. Think about it. It is practically just not possible. By implementing this (so called) feature you are inviting a fault in your menu functionality. Now, the optimism part: May be your requirement is that you do not want your user to reach Item 3 and 4. Then, this could be one of the innovative ways. However, in that case, I would have simply preferred disabling the items.

                              skhan17 wrote:

                              Finally thank you Alan N for helping me out.

                              Welcome... I do think i have helped you... Provided you understand the problem here.

                              S 1 Reply Last reply
                              0
                              • S Som Shekhar

                                Dude!! I am not seeing the glass as half empty buddy... There is a fine line between optimism and hallucination. I am always there standing next to you on optimism and I would always prefer to see the glass as half full... I only reasoned my doubt that how would you go to Menu Item number 3 in your example. Think about it. It is practically just not possible. By implementing this (so called) feature you are inviting a fault in your menu functionality. Now, the optimism part: May be your requirement is that you do not want your user to reach Item 3 and 4. Then, this could be one of the innovative ways. However, in that case, I would have simply preferred disabling the items.

                                skhan17 wrote:

                                Finally thank you Alan N for helping me out.

                                Welcome... I do think i have helped you... Provided you understand the problem here.

                                S Offline
                                S Offline
                                Som Shekhar
                                wrote on last edited by
                                #15

                                In any case, I am sure you don't believe me. So here is a code made for you. Run it and you will see it.

                                public class Form2 : Form
                                {
                                private System.ComponentModel.IContainer components = null;

                                    protected override void Dispose(bool disposing)
                                    {
                                        if (disposing && (components != null))
                                        {
                                            components.Dispose();
                                        }
                                        base.Dispose(disposing);
                                    }
                                
                                    private void InitializeComponent()
                                    {
                                        this.menuStrip1 = new System.Windows.Forms.MenuStrip();
                                        this.item1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                                        this.item1ToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
                                        this.item2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                                        this.item3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                                        this.item4ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                                        this.subItem1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                                        this.subItem2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                                        this.menuStrip1.SuspendLayout();
                                        this.SuspendLayout();
                                        this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem\[\] {
                                        this.item1ToolStripMenuItem});
                                        this.menuStrip1.Location = new System.Drawing.Point(0, 0);
                                        this.menuStrip1.Name = "menuStrip1";
                                        this.menuStrip1.Size = new System.Drawing.Size(491, 24);
                                        this.menuStrip1.TabIndex = 0;
                                        this.menuStrip1.Text = "menuStrip1";
                                        this.item1ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem\[\] {
                                        this.item1ToolStripMenuItem1,
                                        this.item2ToolStripMenuItem,
                                        this.item3ToolStripMenuItem,
                                        this.item4ToolStripMenuItem});
                                        this.item1ToolStripMenuItem.Name = "item1ToolStripMenuItem";
                                        this.item1ToolStripMenuItem.Size = new System.Drawing.Size(77, 20);
                                        this.item1ToolStripMenuItem.Text = "MainMenu";
                                        this.item1ToolStripMenuItem.MouseMove += new System.Windows.Forms.MouseEventHandler(this.item1ToolStripMenuItem\_MouseMove);
                                        this.item1ToolStripMenuItem1.Name = "item1ToolStripMenuItem1";
                                        this.item1ToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
                                        this.item1ToolStripMenuItem1.Text = "I
                                
                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups