Hello,
just like the title said, is there a way to put mouse events, keyboard events or any type of events into if statements? if so how, can you list a couple of examples?
Thank you
mouse events or any events in if statements
Started by Siten0308, Jul 06 2009 06:57 AM
6 replies to this topic
#1
Posted 06 July 2009 - 06:57 AM
|
|
|
#2
Posted 15 July 2009 - 03:53 PM
Do you mean assign an event based on an if statement?
private void button4_Click(object sender, EventArgs e)
{
if (sender == button1)
button1.Click += new EventHandler(button1_Click);
else if (sender == button2)
button2.Click += new EventHandler(button2_Click);
}
#3
Posted 17 July 2009 - 08:46 AM
Or did you mean call the button_Click Handle event manually without the button actually being pressed?
if(!buttonHasBeenPressedBeforeTimeOut) button1_Click(null,null);this probably isn't what you meant but with what scottk has up above as well you should be covered.
#4
Posted 17 July 2009 - 02:24 PM
What are you trying to achieve?
#5
Posted 23 July 2009 - 01:10 AM
This could also be adding delegates to events, with if-statements within. I do not think that was the question though.
private void Form1_Load(object sender, EventArgs e)
{
button1.Click += new EventHandler(button1_Click);
}
void button1_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
proudly presenting my personal website and game website: F1Simulation. a thrilling Managed DirectX racing game... also my Ask Me
look at my tutorials about cropping images and Mono: bundling Mono with programs and lambda expressions
look at my tutorials about cropping images and Mono: bundling Mono with programs and lambda expressions
#6
Posted 29 July 2009 - 01:27 AM
If color of buttons background is white and i click on it with Button2 from the mouse then the counter2 should increase by one. All of the mouse listeners and events are working so is the Label and all the int's. It's just the statement is not increasing the counter when the action is performed.
#7
Posted 30 July 2009 - 03:42 AM
Eusébio Jaime said:
If color of buttons background is white and i click on it with Button2 from the mouse then the counter2 should increase by one. All of the mouse listeners and events are working so is the Label and all the int's. It's just the statement is not increasing the counter when the action is performed.
If you are wanting a counter to increment when the button is clicked you need to increment it inside of the event. It would also be helpful if you posted your code. Your if statement should be something like this:
This block is more or less pseudo code. I'm not sure if it is complete but you should get the idea.
private void button2_Click(object sender, EventArgs e)
{
if( button2.background == white )
{
counter2++;
}
}
-CDG10620
Software Developer
Software Developer


Sign In
Create Account


Back to top









