0

I want to move mouse and click on control in run time. But between form initialize and show form to user was delay about 1 second and this cause mouse clicked on the parent form of this form. I use Show method, Load method but not fix my problem. i don't use timer. How can i fix this? thanks.

my code to click on control is here:

private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
[DllImport("user32.dll")]
private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, uint dwExtraInf);
int x = Convert.ToInt16(trvPointTitls.Location.X+trvPointTitls.Width-10);
int y = Convert.ToInt16(trvPointTitls.Location.Y-10);
Cursor.Position = new Point(x, y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Hajitsu
  • 764
  • 17
  • 49
  • It is **very** unclear why you need to use this hack to click a control. Use trvPointTitls.PerformClick() instead. Or just move the code in the Click event handler into a helper method and call that method directly. Otherwise, your cursor position is wrong, it must be specified in screen coordinates. Use the control's PointToScreen() method. -10 is wrong as well. – Hans Passant Oct 07 '12 at 14:11
  • because of this [^](http://stackoverflow.com/questions/12277012/merging-two-rtf-fields-showed-in-bad-style), i force to use this solution and this solution are fix my problem – Hajitsu Oct 08 '12 at 06:52

0 Answers0