Zebra0.com

csharp boolean

The code below uses a Boolean expression that said to display "Left" if the mouse was on the left, or "Right" otherwise.
Notice that the X and Y value display and the word "Left" or "Right" is concatenated to that using +=.

In the properties of the form, click the and select the MouseMove event. Write the code as shown below:

 private void Form1_MouseMove(object sender, MouseEventArgs e)
 {
    this.Text = "X=" + e.X + " Y=" + e.Y;
    if(e.X <this.Width/2)
    {
       this.Text += " Left";
    }
    else
    {
       this.Text += " Right";
    }
}

Experiment: Change the code above to display "Top" or "Bottom"

End of lesson, Next lesson: