Repositioning the cursor
-
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"); }
-
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"); }
That sounds user-hostile -- I wouldn't use your application if it did that.
-
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"); }
-
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....
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 worksWith great code, comes great complexity, so keep it simple stupid...:-\ :-\
-
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 worksWith great code, comes great complexity, so keep it simple stupid...:-\ :-\
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......
-
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......
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...:-\ :-\
-
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...:-\ :-\
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...:-\ :-\
-
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....
skhan17 wrote:
all the supervisors in the MSc. program are crazy
I can imagine. I have no idea, but will Focus have any effect?
-
skhan17 wrote:
all the supervisors in the MSc. program are crazy
I can imagine. I have no idea, but will Focus have any effect?
-
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"); }
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.
-
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.
-
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"); }
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
-
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
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.
-
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.
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.
-
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.
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