How can i check on pictureBox1 mouse leave event if the user is in mouse down event ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
What i mean is that i want to activate the mouse leave event only when the user is moving the mouse pointer out of the pictureBox1 client area only if he press down the left mouse button once the user dosent press the left mouse button he can move the mouse
around free and the event wont do anything.

I have a variable in the top of Form1 called mouseLeave type bool.
In constructor i made it to be false;
In the pictureBox1 mouse down event i did the mouseLeave variable to be true.

<pre class="prettyprint private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
label1.Visible = true;
label4.Visible = true;
// find the index that is closest to the current mouse location
float t = wireObject1.GetIndexByXY(e.X, e.Y, 5);

if (t == -1)
{
button3.Enabled = false;
}
else
{
button3.Enabled = true;
{
selectedIndex = t;
mouseMove = true;
mouseLeave = true;[/code]
<br/>

In the pictureBox1 mouse move event i check if mouseMove is true then move the point drag it around:

<pre class="prettyprint private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (mouseMove == true)
{
Point NewPoint = e.Location;
{

wireObject1.MovePoint(selectedIndex, NewPoint, NewPoint); // when moving a point dragging the other point is vanished deleted. To check why !

label1.Text = "{X = " + NewPoint.X + "}" + " " + "{Y = " + NewPoint.Y + "}";
pictureBox1.Refresh();
}

}
else
{
label19.Text = "{X = " + e.X + "}" + " " + "{Y = " + e.Y + "}";
}
}[/code]
So when the user click on the mouse left button without leave it and drag the point then the point will move aorund the pictureBox1 client area.

Now in the pictureBox1 mouse leave event i did:

<pre class="prettyprint private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
if (mouseLeave == true)
{
mouseMove = false;
}

}[/code]
<br/>
But it dosent work. I add a point drag it move it around but this event activate do something only when i move the mouse pointer out of the pictureBox1 area without dragging the point only when im not clicking down the left mouse button.
What i want is that only when i click down the mouse left button and move it around like in the mouse move event only then this leave event will do something in this case will make mouseMove to be false.

So the user will not be able to drag the point out of the pictureBox1 area. What should i do in the mouse leave event then ?

<hr class="sig danieli

View the full article
 
Back
Top