ऐसा करने का कोई साफ तरीका नहीं है। user32.dll
से mouse_event
फ़ंक्शन का उपयोग करने का एकमात्र तरीका है। यह भी आवश्यक है कि आप अस्थायी रूप से कर्सर को वांछित स्थान पर ले जाएं, क्लिक करें, फिर इसे वापस ले जाएं।
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy,
long cButtons, long dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public void ClickMouseLeftButton(Point globalLocation)
{
Point currLocation = Cursor.Position;
Cursor.Position = globalLocation;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,
globalLocation.X, globalLocation.Y, 0, 0);
Cursor.Position = currLocation;
}
public void ClickControl(Control target, Point localLocation)
{
ClickMouseLeftButton(target.PointToScreen(localLocation));
}
public void ClickControl(Control target)
{
ClickControl(target, new Point(target.Width/2, target.Height/2));
}
वैकल्पिक रूप से, अगर आप एक एक्सटेंशन विधि में इस बदल सकता है:
public static class ControlExtensions
{
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
private static extern void mouse_event(long dwFlags, long dx, long dy,
long cButtons, long dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
private static void ClickMouseLeftButton(Point globalLocation)
{
Point currLocation = Cursor.Position;
Cursor.Position = globalLocation;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,
globalLocation.X, globalLocation.Y, 0, 0);
Cursor.Position = currLocation;
}
public static void ClickMouse(this Control target, Point localLocation)
{
ClickMouseLeftButton(target.PointToScreen(localLocation));
}
public static void ClickMouse(this Control target)
{
ClickMouse(target, new Point(target.Width/2, target.Height/2));
}
}
यह अनुमति देगा आप कॉल करना controlName.ClickMouse();
स्रोत
2010-07-01 16:50:22
आप किस तकनीक का उपयोग कर रहे हैं? WinForms? WPF? ASP.NET? सिल्वरलाइट? –
वह (या वह?) पहले ही उल्लेख कर चुका है। –
एनिमेटेड gif? शायद कुछ – CheeseConQueso