gborges
November 24th, 2008, 12:14 PM
Hi all!
I am in trouble trying to positioning a context menu strip.
I will explain my application, here.
There is a usercontrol, which the user can right click using mouse and so, I would like that a customized menu appers, just after this action.
I create a context menu, using this code:
private void InitializeContextMenu() {
this.components = new System.ComponentModel.Container();
this.ticksMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ticksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tenthMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.seventhMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ticksMenuStrip.SuspendLayout();
this.SuspendLayout();
//
// ticksMenuStrip
//
this.ticksMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ticksToolStripMenuItem});
this.ticksMenuStrip.Name = "ticksMenuStrip";
this.ticksMenuStrip.Size = new System.Drawing.Size(153, 48);
//
// ticksToolStripMenuItem
//
this.ticksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tenthMenuItem,
this.seventhMenuItem});
this.ticksToolStripMenuItem.Name = "ticksToolStripMenuItem";
this.ticksToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.ticksToolStripMenuItem.Text = "Ticks";
//
// tenthMenuItem
//
this.tenthMenuItem.Name = "tenthMenuItem";
this.tenthMenuItem.Size = new System.Drawing.Size(152, 22);
this.tenthMenuItem.Text = "1/10 of scale";
this.tenthMenuItem.Click += new System.EventHandler(this.tenthMenuItem_Click);
//
// seventhMenuItem
//
this.seventhMenuItem.Name = "seventhMenuItem";
this.seventhMenuItem.Size = new System.Drawing.Size(152, 22);
this.seventhMenuItem.Text = "1/7 of scale";
this.seventhMenuItem.Click += new System.EventHandler(this.seventhMenuItem_Click);
//
//
//
this.ticksMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
}
I get the mouse right click using this code:
protected override void controlEx_MouseDown(Object sender, MouseEventArgs e) {
switch (e.Button) {
case MouseButtons.Right:
this.ticksMenuStrip.Show();
break;
}
return;
}
The problem is that when I right-click over the user control the context menu appears on top left position of the screen, but I would like that it appears just where I click using the mouse.
I read that I would add a notifyIcon in order to do it, but it also does no works.
Could someone help me?
Thank you in advance!
I am in trouble trying to positioning a context menu strip.
I will explain my application, here.
There is a usercontrol, which the user can right click using mouse and so, I would like that a customized menu appers, just after this action.
I create a context menu, using this code:
private void InitializeContextMenu() {
this.components = new System.ComponentModel.Container();
this.ticksMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ticksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tenthMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.seventhMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ticksMenuStrip.SuspendLayout();
this.SuspendLayout();
//
// ticksMenuStrip
//
this.ticksMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ticksToolStripMenuItem});
this.ticksMenuStrip.Name = "ticksMenuStrip";
this.ticksMenuStrip.Size = new System.Drawing.Size(153, 48);
//
// ticksToolStripMenuItem
//
this.ticksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tenthMenuItem,
this.seventhMenuItem});
this.ticksToolStripMenuItem.Name = "ticksToolStripMenuItem";
this.ticksToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.ticksToolStripMenuItem.Text = "Ticks";
//
// tenthMenuItem
//
this.tenthMenuItem.Name = "tenthMenuItem";
this.tenthMenuItem.Size = new System.Drawing.Size(152, 22);
this.tenthMenuItem.Text = "1/10 of scale";
this.tenthMenuItem.Click += new System.EventHandler(this.tenthMenuItem_Click);
//
// seventhMenuItem
//
this.seventhMenuItem.Name = "seventhMenuItem";
this.seventhMenuItem.Size = new System.Drawing.Size(152, 22);
this.seventhMenuItem.Text = "1/7 of scale";
this.seventhMenuItem.Click += new System.EventHandler(this.seventhMenuItem_Click);
//
//
//
this.ticksMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
}
I get the mouse right click using this code:
protected override void controlEx_MouseDown(Object sender, MouseEventArgs e) {
switch (e.Button) {
case MouseButtons.Right:
this.ticksMenuStrip.Show();
break;
}
return;
}
The problem is that when I right-click over the user control the context menu appears on top left position of the screen, but I would like that it appears just where I click using the mouse.
I read that I would add a notifyIcon in order to do it, but it also does no works.
Could someone help me?
Thank you in advance!