Simulate click event

Superfly1611

Regular
Joined
Feb 17, 2004
Messages
66
Location
UK
Hi,

I am trying to simulate a PictureBox.Click event using the Compact Framework 1.0. I have searched these forums and the ones on MSDN with many different combinations of search terms but I cant find anything.

Basically what I am trying to achieve is to fire the picturebox's click event from within my code. What I have read so far seems to indicate that I need to make a call to SendMessage (COM interop?) to actually make windows perform the click.

The other method that I am investigating is the use of the mouse_event as demonstrated in this article by Daniel Moth.

However I am struggling to find the namespace Win32Api anywhere in the framework so I'm struggling with that also.

This is for the compact framework version 1.0.

Any help you can give would be great because this is all very new to me, I'm a web application developer by trade so i'm a fish out of water on this one!
 
*Update*

I have been able to simulate a click using mouse_event in a call to the coredll using the following code:
Code:
[DllImport("coredll")]
static extern bool SetCursorPos(int X, int Y);

[DllImport("coredll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);

[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}

bool tempVal = SetCursorPos(x, y);
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
however I have one outstanding problem (that I know of!).

I am struggling to capture the corrext X and Y co-ordinates of the control. I have tried many different methods and they all return values of 0 for both axis.

How do you guys do it?

Many Thanks
 
Back
Top