How do you paint the titlebar of a form?

  • Thread starter Thread starter Gregory Hawke
  • Start date Start date
G

Gregory Hawke

What would be the easiest way of painting a titlebar in a form?

Setting the background property of a derived System.Windows.Forms.Form only
paints the client area. I need to paint the frame as well but when I tried

this.ParentForm=System.Drawing.Color.Crimson;

I get an error: Property or Indexer cannot be assigned to -- it is read
only.


So is there a way to override this read only property for a forms frame?
 
Gregory,

If you want to paint the titlebar (or paint on it), you need to handle
the WM_NCPAINT message in the WndProc method on your form. This message is
sent when the frame of a window needs to be painted.

Hope this helps.
 
Are you from a C++ background?

The Titlebar colors are determined by system settings or themes. They apply
to all windows and cannot easily be manipulated. You would have to draw
directly to the frame during NC paint events or replace the titlebar with a
custom control and implement the windowing functionality yourself. Painting
in the non-client area would be easiest, when you remove the frame from a
window it strips a lot of Windows functionality away with it.

I implemented a custom titlebar control in VB6, but have not yet ported it
to .NET.

HTH;
Eric Cadwell
http://www.origincontrols.com
 
Back
Top