首页 > 解决方案 > Delphi:重叠窗口/表单标题栏?

问题描述

是否可以将表单标题栏与其他控件(TPanel)重叠?

像这样的东西:

标签: formsdelphiwindow

解决方案


正如Jerry 评论的那样,也许您可​​以使用放置面板的 StayOnTop 表单。假设您将该面板设计为主窗体上的(可能左对齐)控件,则此类解决方案的开头可能如下所示:

uses
  Winapi.Windows, Winapi.Messages, System.Classes, Vcl.Controls, Vcl.Forms,
  Vcl.ExtCtrls;

type
  TMainForm = class(TForm)
    Panel1: TPanel;
  private
    FStickIt: TForm;
  protected
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
    procedure WMWindowPosChanged(var Message: TWMWindowPosChanged);
      message WM_WINDOWPOSCHANGED;
  public
    constructor Create(AOwner: TComponent); override;
  end;

implementation

{$R *.dfm}

constructor TMainForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FStickIt := TForm.CreateNew(Self);
  FStickIt.AutoSize := True;
  FStickIt.BorderStyle := bsNone;
  FStickIt.FormStyle := fsStayOnTop;
  FStickIt.Show;
  Panel1.Align := alCustom;
  Panel1.Parent := FStickIt;
end;

procedure TMainForm.WMSysCommand(var Message: TWMSysCommand);
begin
  inherited;
  case Message.CmdType and $FFF0 of
    SC_MINIMIZE: FStickIt.Hide;
    SC_RESTORE: FStickIt.Show;
  end;
end;

procedure TMainForm.WMWindowPosChanged(var Message: TWMWindowPosChanged);
var
  EdgeSize: Integer;
  TitleBarInfoEx: TTitleBarInfoEx;
begin
  inherited;
  if Assigned(FStickIt) then
  begin
    EdgeSize := (Width - ClientWidth) div 2;
    FStickIt.Left := Left + EdgeSize - BorderWidth;
    FStickIt.Top := Top + GetSystemMetrics(SM_CYBORDER);
    Panel1.Height := Height - EdgeSize - GetSystemMetrics(SM_CYBORDER) +
      BorderWidth;
    TitleBarInfoEx.cbSize := SizeOf(TitleBarInfoEx);
    SendMessage(Handle, WM_GETTITLEBARINFOEX, 0, LPARAM(@TitleBarInfoEx));
    Constraints.MinWidth := Panel1.Width + TitleBarInfoEx.rgrect[5].Right -
      TitleBarInfoEx.rgrect[2].Left + 2 * EdgeSize - 2 * BorderWidth;
  end;
end;

推荐阅读