[DllImport("coredll.dll")]
static extern IntPtr GetCapture();
Declare Function GetCapture Lib "coredll.dll" () As IntPtr
None.
None.
You can use GetCapture in conjunction with SetCapture to obtain the window handle of a Control. See the sample code below.
public IntPtr GetHWnd(Control ctrl)
{
IntPtr hOldWnd = GetCapture();
ctrl.Capture = true;
IntPtr hWnd = GetCapture();
ctrl.Capture = false;
SetCapture(hOldWnd);
return hWnd;
}
{
private const int RequiredWidth = 200;
private const int RequiredHeight = 148;
private void Form_Load(object sender, System.EventArgs e)
{
this.Capture = true;
IntPtr hWnd = GetCapture();
SetWindowPos(hWnd,
hWnd,
(Screen.PrimaryScreen.Bounds.Width-RequiredWidth)/2,
30,
RequiredWidth,
RequiredHeight,
0);
}
[DllImport("coredll.dll")]
static extern IntPtr GetCapture();
[DllImport("coredll.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
int Y, int cx, int cy, uint uFlags);
}
None