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
multiple events
Started by Siten0308, Jul 01 2009 10:54 AM
6 replies to this topic
#1
Posted 01 July 2009 - 10:54 AM
|
|
|
#2
Posted 06 July 2009 - 05:14 AM
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
Software Developer
#3
Posted 06 July 2009 - 05:29 AM
Have both of the events execute the same function.
#4
Posted 06 July 2009 - 05:34 AM
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
Software Developer
#5
Posted 06 July 2009 - 06:56 AM
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.
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
Posted 06 July 2009 - 08:27 AM
Posting to code to see how you solved the problem would be helpful.
-CDG10620
Software Developer
Software Developer
#7
Posted 06 July 2009 - 08:32 AM
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:
the next thing is using if statement to say if answer is == true, which is triggered by mousedown, then enable mousemove:
cool huh, but to simplify everything into 4 lines of code, using the following code below:
Hope this helps someone understand events as it did for me.
Thanks again for all input
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


Sign In
Create Account


Back to top









