Hi and thanks. The solution works fine.
A few tips for others who have the same problem. GetNextWindow didn't work for me - DllImport said there's no such function as GetNextWindow, so it's probably just a buffer name for GetWindow used in user32.lib import library. As the documentation said though - GetWindow works just about the same and can be easily imported in C#.
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern bool SetWindowPos(
IntPtr hWnd, // window handle
IntPtr hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags); // window positioning flags
public const uint SWP_NOSIZE = 0x1;
public const uint SWP_NOMOVE = 0x2;
public const uint SWP_SHOWWINDOW = 0x40;
public const uint SWP_NOACTIVATE = 0x10;
[DllImport("user32.dll", EntryPoint = "GetWindow")]
public static extern IntPtr GetWindow(
IntPtr hWnd,
uint wCmd);
public const uint GW_HWNDFIRST = 0;
public const uint GW_HWNDLAST = 1;
public const uint GW_HWNDNEXT = 2;
public const uint GW_HWNDPREV = 3;
public static void ControlBringToFront(Contro
{
bool s = SetWindowPos(
control.Handle,
GetWindow(GetWindow(contro
0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
public static void ControlSendToBack(Control control)
{
bool s = SetWindowPos(
control.Handle,
GetWindow(control.Handle, GW_HWNDLAST),
0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
public static void ControlBringForward(Contro
{
if (GetWindow(control.Handle,
return;
SetWindowPos(
control.Handle,
GetWindow(GetWindow(contro
0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
public static void ControlSendBackward(Contro
{
if (GetWindow(control.Handle,
return;
SetWindowPos(
control.Handle,
GetWindow(control.Handle, GW_HWNDNEXT),
0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
--------------------------
What is interesting, .NET's Control class' Controls property returns the collection of controls ordered in their Z-Order, so after you design the whole collection you can store it in some resource file in the order from Control.Controls and when you read the form back - the controls will be in the same Z-Order you designed them to be in.
Main Topics
Browse All Topics





by: jaime_olivaresPosted on 2004-12-04 at 10:45:25ID: 12744990
You have to build a "list" of neighbours using GetNextWindow() function. Then, you have the list of control in specific Z-Order, when you want to "bring forward", just find next window to use as reference in SetWindowPos. library/de fault.asp? url=/libra ry/ en-us/w inui/winui /windowsus erinterfac e/windowin g/windows/ windowrefe rence/wind owfunction s/getnextw indow.asp library/en -us/winui/ winui/ wind owsuserint erface/win dowing/win dows/windo wreference / windowfun ctions/set windowpos. asp
Have a look to:
http://msdn.microsoft.com/
http://msdn.microsoft.com/