"Simulate"/Invoke Click event

M

minimega

Hello to all NG,
I've a class that manage the OpenNETCF.ButtonEx control. I add the
control to myForm, then via code I use myClass.Add(buttonEx) and my
class manage all the graphics layout, color, mouseover/mouseexit events
and so on. In myForm I subscribe the .Click event to get events from
the button, however, when the control has the focus and the user press
the Enter/SpaceBar key I want to get the KeyPress event as a Click
event. Now, I'm thinking to manage the .KeyPress event in myClass (so
is valid for ALL the forms that use that class), but I've the problem
to "translate" then KeyPress event (subscribed and raised) in myClass
to Click event (sibscribed and raised) in myForm. There is a way to do
this (using Reflection??)

Thanks,
Massimo
 
D

Daniel Moth

Not sure I am with you all the way but maybe what you are looking for is the
PerformClick method on ButtonEx. (call it form your keypress method and it
will simulate a Click)

Cheers
Daniel
 
M

minimega

Hi Daniel, thanks for your reply.
I just found this (working) solution:

MethodInfo method = sender.GetType().GetMethod("OnMouseUp",
BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(sender, new object[]{new
System.Windows.Forms.MouseEventArgs(System.Windows.Forms.MouseButtons.Left,
0, 0, 0, 0)});

That's seems to work very fine and can be used with any control (not
only with ButtonEx).

Bye,
minimega
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top