Mirror

Hide and show the title bar of a TForm (Views: 101)


Problem/Question/Abstract:

How to hide and show the title bar of a TForm

Answer:

Here is how to hide the titlebar:

procedure TYourFormName.HideTitlebar;
var
  Save: LongInt;
begin
  if BorderStyle = bsNone then
    Exit;
  Save := GetWindowLong(Handle, GWL_STYLE);
  if (Save and WS_CAPTION) = WS_CAPTION then
  begin
    case BorderStyle of
      bsSingle, bsSizeable:
        SetWindowLong(Handle, GWL_STYLE, Save and (not (WS_CAPTION)) or WS_BORDER);
      bsDialog:
        SetWindowLong(Handle, GWL_STYLE, Save and (not (WS_CAPTION)) or DS_MODALFRAME
          or WS_DLGFRAME);
    end;
    Height := Height - GetSystemMetrics(SM_CYCAPTION);
    Refresh;
  end;
end;

And here is how we show it again:

procedure TYourFormName.ShowTitlebar;
var
  Save: LongInt;
begin
  if BorderStyle = bsNone then
    Exit;
  Save := GetWindowLong(Handle, GWL_STYLE);
  if (Save and WS_CAPTION) <> WS_CAPTION then
  begin
    case BorderStyle of
      bsSingle, bsSizeable:
        SetWindowLong(Handle, GWL_STYLE, Save or WS_CAPTION or WS_BORDER);
      bsDialog:
        SetWindowLong(Handle, GWL_STYLE, Save or WS_CAPTION or DS_MODALFRAME or
          WS_DLGFRAME);
    end;
    Height := Height + GetSystemMetrics(SM_CYCAPTION);
    Refresh;
  end;
end;

<< Back to main page