I am new to C# and am creating a C# Windows Mobile application that I need to programmatically invoke the click event on a Button. I have looked at the Button class and do not see a way to do this.
Any ideas?
Zzub
I am new to C# and am creating a C# Windows Mobile application that I need to programmatically invoke the click event on a Button. I have looked at the Button class and do not see a way to do this.
Any ideas?
Zzub
You might consider changing your design: at least move the logic from button1_Click handler somewhere else so that you'll be able to invoke it from wherever you want.
Anything that prevents you from simply invoking the method that handles the onClick event?
On the full blown .NET side you can call:
this.button1.PerformClick();
Not sure if that works on WindowsMobile. You're other option is to do something like this:
private void button1_Click(object sender, EventArgs e)
{
OnButtonClick();
}
private void OnButtonClick()
{
}
Then you can call your OnButtonClick() wherever you need to.
Not exactly the answer you were probably looking for:::
You might just call the code you want to run, move the meat of the code outside the OnClick handling method. The OnClick method could fire that method the same as your code.
He wants the button graphic to move as well, just as if the mouse was clicked on it, however the mouse was not actually clicked on it. Do not question his motivation, or suggest that you cant think of any reason it should be done, just tell him how to do it. Perhaps he has an external button connected via a digital input (usb based interface card), this button must act just like a left button click whilst also allowing the mouse to work, in this case it would be nice to trigger a mouse click method whenever he d*amn well wants. And see the button graphic move down, not just call some lame method that is invoked by the button click event.