Click here to Skip to main content
13,190,405 members (52,720 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 21 Dec 2010

Unfocusable, borderless form, perfect for floating controls!

, 22 Dec 2010
Rate this:
Please Sign up or sign in to vote.
Unfocusable, borderless form, perfect for floating controls!
First of all, I did not discover this thing. I do not remember where I've got it from, sorry. I am putting it here just to help others who need it.

For this trick, you need the following external function:

[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();

Now, in the form that you want unfocusable (but still usable), add the following override:

protected override CreateParams CreateParams
        var cp = base.CreateParams; // Retrieve the normal parameters.
        cp.Style = 0x40000000 | 0x4000000; // WS_CHILD | WS_CLIPSIBLINGS
        cp.ExStyle &= 0x00080000; // WS_EX_LAYERED
        cp.Parent = GetDesktopWindow(); // Make "GetDesktopWindow()" from your own namespace.
        return cp;

Show this form with only with the overloaded Show(IWin32Window owner) method. The "owner" window will always keep the unfocusable form over it and never lose focus when the unfocusable form should be focused.

Moving focus to the unfocusable form from a window other than its owner will draw the focus away.

You can add any controls you like on this form and still sleep well at night; they will work perfectly, but will just not get focus!

Style and ExStyle values taken from WinUser.h of Microsoft Windows SDK.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Romania Romania
A 17-year-old whose passion is programming, mostly in C# and Lua.

You may also be interested in...


Comments and Discussions

PraiseI tried everything and this is the solution! Pin
memberRIVASBROTHERS12-Apr-17 9:04 
AnswerWelldone Pin
Omid Rezaei Nejad10-May-13 14:01
memberOmid Rezaei Nejad10-May-13 14:01 
GeneralMy vote of 5 Pin
Omid Rezaei Nejad10-May-13 14:00
memberOmid Rezaei Nejad10-May-13 14:00 
Questionmy vote of 5 Pin
Seyed Mahmoud Bakhtvar18-Jun-12 6:27
memberSeyed Mahmoud Bakhtvar18-Jun-12 6:27 
GeneralReason for my vote of 5 Very effective and simple as breath ... Pin
imgen28-Dec-10 2:22
memberimgen28-Dec-10 2:22 
GeneralYou're welcome! :D Pin
Vercas22-Dec-10 0:03
memberVercas22-Dec-10 0:03 
GeneralThanks! Pin
Walt Fair, Jr.21-Dec-10 15:50
subeditorWalt Fair, Jr.21-Dec-10 15:50 
QuestionFloating toolbars in MDI environment Pin
LorenzoSacco6-Feb-12 4:53
memberLorenzoSacco6-Feb-12 4:53 
AnswerRe: Floating toolbars in MDI environment Pin
Vercas6-Feb-12 9:21
memberVercas6-Feb-12 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171016.2 | Last Updated 22 Dec 2010
Article Copyright 2010 by Vercas
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid