Nick Peelman
Nick Peelman

Reputation: 583

When are control events used in code?

When using the windows form app, you can create an event for example a picturebox.Click event. Inside this method all code will be ran when the butten is clicked.

Now inside another event, I can call the method Button1.click, but what is it used for? Can it be used for statements like this?

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
    if(Button1.click == true) // If the button is clicked AND the mouse moves over the picturebox
    {
        //dance
    }
}

Upvotes: 0

Views: 69

Answers (1)

CodeCaster
CodeCaster

Reputation: 151604

No, you'll have to store a state. Where and how you do this can differ, but consider this:

var yourObject = new ObjectYouWishToControl();

...

private void Button1_Click(object sender, MouseEventArgs e)
{
    yourObject.Button1WasClicked = true;
}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
    if (yourObject.Button1WasClicked)
    {
        // do your thing
    }
}

Upvotes: 3

Related Questions