Maximise or show a window without giving it focus

P

PaulR

Hi,

Is there a way of maximising a form without having it
grab the window focus?

Thanks
 
B

Bob Powell [MVP]

You have to use interop. Import the ShowWindow method from user32 and call
the method with the SW_SHOWNOAVTIVATE constant.

[DllImport("User32.dll")]

public extern static int ShowWindow( System.IntPtr hWnd, short cmdShow);

[Flags()]

public enum ShowWindow

{

SW_HIDE = 0,

SW_SHOWNORMAL = 1,

SW_NORMAL = 1,

SW_SHOWMINIMIZED = 2,

SW_SHOWMAXIMIZED = 3,

SW_MAXIMIZE = 3,

SW_SHOWNOACTIVATE = 4,

SW_SHOW = 5,

SW_MINIMIZE = 6,

SW_SHOWMINNOACTIVE = 7,

SW_SHOWNA = 8,

SW_RESTORE = 9,

SW_SHOWDEFAULT = 10,

SW_FORCEMINIMIZE = 11,

SW_MAX = 11

}

The call below does the job

ShowWindow(myWindow.Handle,(short)ShowWindow.SW_SHOWNOACTIVATE);


--
Bob Powell [MVP]
C#, System.Drawing


Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm

New Tips and Tricks include creating transparent controls
and how to do double buffering.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top