no title bar but still have window caption for alt-tab

J

jay.meerdink

Is there a way to set the text for a window, but not paint the title
bar? I can set the text to nothing and turn off the control box to
prevent the title bar from rendering, but then there's no text for the
program in the taskbar or in alt-tab. And as soon as I specify text
for the window caption, the title bar is rendered. Thanks for your
help.
 
N

Nicholas Paldino [.NET/C# MVP]

You will have to custom paint the frame of the window in order to do
this. In order to do this, you will have to override the WM_NCPAINT message
in the WndProc method on the form and choose to not paint the border.
 
M

Mick Doherty

Override CreateParams and remove the WS_CAPTION style.

\\\
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
System.Windows.Forms.CreateParams cp = base.CreateParams;
cp.Style &= ~0x00C00000; // WS_CAPTION
return cp;
}
}
///
 
J

jay.meerdink

Override CreateParams and remove the WS_CAPTION style.

\\\
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
System.Windows.Forms.CreateParams cp = base.CreateParams;
cp.Style &= ~0x00C00000; // WS_CAPTION
return cp;
}}

///

--
Mick Dohertyhttp://www.dotnetrix.co.uk/nothing.html






- Show quoted text -

I did try

protected override void WndProc(ref Message m)
{
if (m.Msg != 0x0085) base.WndProc(ref m);
else Debug.WriteLine(m.Msg.ToString());
}

to see if I could get the form to render with no border or title bar -
it sort of worked. Got wierd artifacts on the screen where the title
bar would have been, and still couldn't set the text without the title
bar appearing.

This bit with CreateParams works like a champ, but I'm not sure what's
happening. Am I masking out all of the title bar options except the
caption?

Thanks so much for the tips!
 
M

Mick Doherty

This bit with CreateParams works like a champ, but I'm not sure what's
happening. Am I masking out all of the title bar options except the
caption?

Thanks so much for the tips!

The WS_CAPTION style is set on any window which has a titlebar (Add the
style to a Button and see what happens). These styles are applied when the
Window is created and behind the scenes dotnet is just calling
CreateWindowEx() with all the necessary parameters. By overriding
CreateParams we are able to change these parameters.

You'll find out more about these options by looking at the documentation for
CreateWindowEx():
http://msdn2.microsoft.com/en-us/library/ms632680.aspx
http://msdn2.microsoft.com/en-us/library/czada357(VS.71).aspx
 

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