C
Charles Crawford
Hello,
I'm writing a windows forms application and have a custom user control built
from multiple controls, including a picturebox control onto which I'm
drawing a clock face. Each hour on the clock face represents a 'node' and I
have the application switch cursors from the arrow to hand cursors each time
the mouse moves over one of the nodes.
I have a contextmenustrip control assigned to the picturebox control, but I
only wish to display the context menu when the mouse is over one of the
nodes.
I've tried to use the mousedown event on the picturebox as follows:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right && pictureBox1.Cursor ==
Cursors.Hand)
{
pictureBox1.Cursor = Cursors.Arrow;
contextMenuStrip1.Visible = true;
}
else
{
contextMenuStrip1.Visible = false;
}
}
The problem I'm having is that the context menu shows up whenever I
right-click on the picturebox, regardless of whether it's over a 'node' or
not.
Thanks in advance.
Charlie
I'm writing a windows forms application and have a custom user control built
from multiple controls, including a picturebox control onto which I'm
drawing a clock face. Each hour on the clock face represents a 'node' and I
have the application switch cursors from the arrow to hand cursors each time
the mouse moves over one of the nodes.
I have a contextmenustrip control assigned to the picturebox control, but I
only wish to display the context menu when the mouse is over one of the
nodes.
I've tried to use the mousedown event on the picturebox as follows:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right && pictureBox1.Cursor ==
Cursors.Hand)
{
pictureBox1.Cursor = Cursors.Arrow;
contextMenuStrip1.Visible = true;
}
else
{
contextMenuStrip1.Visible = false;
}
}
The problem I'm having is that the context menu shows up whenever I
right-click on the picturebox, regardless of whether it's over a 'node' or
not.
Thanks in advance.
Charlie