PDA

View Full Version : سوال: مشکل با تابع SetFocus از API



Collector
پنج شنبه 27 بهمن 1390, 20:22 عصر
سلام

من با این کد میخوام فوکوس را به فرم Form1 که یک پروسه جدا هست بدم.اما این کد کار نمیکنه؟

[DllImport("User32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("User32.dll")]
public static extern IntPtr SetFocus(IntPtr hWnd);


SetFocus(FindWindow(null, "Form1"));

mrbm_2007
جمعه 28 بهمن 1390, 01:16 صبح
از setforegroundwindow استفاده کن
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

SetForegroundWindow(frm.handle)