2009. március 9., hétfő

Make a TPanel look like the title bar of a window


Problem/Question/Abstract:

I have a good reason why I cannot use forms. So as an alternative I'm using two panels to mimic a simple form, i.e. with no windows icons (close, minimize etc.). One is aligned to the top to pose like the window title bar and the other to client. I want to paint the top panel like a typical title bar. How can I do this?

Answer:

There is an API function named DrawCaption, you can use it to draw the caption bar. Drop a client-aligned TPaintbox on your fake caption panel and do the drawing in the paintboxes OnPaint handler.

procedure TPLabBaseChildform.CaptionPaint(Sender: TObject);
const
  activeFlags: array[Boolean] of DWORD = (0, DC_ACTIVE);
begin
  with Sender as TPaintbox do
    DrawCaption(self.handle, canvas.handle, clientrect, activeFlags[FActive] or
      DC_TEXT or DC_GRADIENT);
end;

To draw other elements as well (beside the icon, which DrawCaption can handle) you use DrawFrameControl instead.

Nincsenek megjegyzések:

Megjegyzés küldése