The previous code used a Boolean expression that said to display "side" if the mouse was on the left OR the right.
We could also have said that the mouse was in the middle if e.X is greater than 10 AND e.X is less than the width of the form minus 20:
In the properties of the form, click the and select the MouseMove event.
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.Text = "X=" + e.X + " Y=" + e.Y;
if(e.X>10 && e.X <this.Width-20)
{
this.Text += " Middle";
}
else
{
this.Text += " Side";
}
}
Experiment: Change the code above to change the caption to "Target area" when the mouse is in each of the shaded areas:
1. 2. 3. 4.
Try writing each problem two ways, once using And, again using Or.
End of lesson, Next lesson: