Jump to content

multiple events

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello,

Probably a simple question for everyone, but what if i want to add to events together, what i mean is lets say i want an action or method to trigger when user holds the mouse button down and moves across, how do i accomplish that? hopefully that is clear enough to understand but again lets say i want to user to left click, mouse button down, then drag over (sorta doing the drag and drop and i know its going to require more than those two events, actually i think those might be it) but if someone can tell me how to use multiple events that would be great.

Thank you

#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
I know that you can have one event call another. As for dragging sometimes objects will have methods that are supplied for that. for instance, list boxes have a dragdrop event to where you can drag and drop items into a list box. Did you look at all of events that are available to you?
-CDG10620
Software Developer

#3
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
Have both of the events execute the same function.

#4
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
You can defiantly have two events call the same function. Having a click event, then a drag event I don't think will help you. The second you click the mouse the click event will fire. There should be a dragdrop event that you can use that will wait until the mouse button is released to fire the event.
-CDG10620
Software Developer

#5
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello,

I think i got what i needed my mentor told me two simple ways of doing it, first was a bool and if it turned to true (which the mouse event triggered it) then execute or use the function that makes the other mouse event trigger as well, so all in all it works, please let me know if anyone would like to see the code for it, also i dont know if i should start another thread for my question, but i guess i will its about if statements and events.

Thanks again everyone for their input.

#6
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Posting to code to see how you solved the problem would be helpful.
-CDG10620
Software Developer

#7
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
ok here is the code below, there are two ways of doing it, first is using a bool variable to equal false, then when a mouse button is clicked, then it will trigger the mouse event:


private void pictureBox1_MouseDown(object sender, MouseEventArgs e)

        {

            

            if (answer == true)

            {

                lblx.Text = "X: " + e.X.ToString();

                lbly.Text = "Y: " + e.Y.ToString();

                answer = true;

            }

            answer = true;

            

        }


the next thing is using if statement to say if answer is == true, which is triggered by mousedown, then enable mousemove:


private void pictureBox1_MouseMove(object sender, MouseEventArgs e)

        {

            if (answer == true)

            {

                lblx.Text = "X: " + e.X.ToString();

                lbly.Text = "Y: " + e.Y.ToString();

            }

         }


cool huh, but to simplify everything into 4 lines of code, using the following code below:


private void pictureBox1_MouseMove(object sender, MouseEventArgs e)

        {

if (e.Button == MouseButtons.Left)

            {

                lblx.Text = "X: " + e.X.ToString();

                lbly.Text = "Y: " + e.Y.ToString();

            }

         }



Hope this helps someone understand events as it did for me.

Thanks again for all input