2

我通过执行以下操作将 ComboBox 添加到标题栏:

  1. 在主窗体上,我将 CustomTitleBar.enabled 设置为 true;
  2. 将 TitleBarPanel 添加到窗体并将 CustomTitleBar.Control 设置为 TitleBarPanel。
  3. 在 TitleBarPanel 上放置一个 ComboBox 并适当地对齐它。

这在我运行它时效果很好,但是如果我将 MainMenu 添加到表单中,则菜单会出现在 TitleBarPanel 下。我已经在网上搜寻解决方案,但没有成功。在 MainMenu 正确显示之前是否还有其他事情需要发生。

这是我的表格:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Custom Title Bar Test'
  ClientHeight = 739
  ClientWidth = 938
  Color = clBtnFace
  CustomTitleBar.Control = TitleBarPanel1
  CustomTitleBar.Enabled = True
  CustomTitleBar.Height = 45
  CustomTitleBar.BackgroundColor = clWhite
  CustomTitleBar.ForegroundColor = 65793
  CustomTitleBar.InactiveBackgroundColor = clWhite
  CustomTitleBar.InactiveForegroundColor = 10066329
  CustomTitleBar.ButtonForegroundColor = 65793
  CustomTitleBar.ButtonBackgroundColor = clWhite
  CustomTitleBar.ButtonHoverForegroundColor = 65793
  CustomTitleBar.ButtonHoverBackgroundColor = 16053492
  CustomTitleBar.ButtonPressedForegroundColor = 65793
  CustomTitleBar.ButtonPressedBackgroundColor = 15395562
  CustomTitleBar.ButtonInactiveForegroundColor = 10066329
  CustomTitleBar.ButtonInactiveBackgroundColor = clWhite
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -18
  Font.Name = 'Segoe UI'
  Font.Style = []
  GlassFrame.Enabled = True
  GlassFrame.Top = 45
  Menu = MainMenu1
  StyleElements = [seFont, seClient]
  PixelsPerInch = 144
  TextHeight = 25
  object TitleBarPanel1: TTitleBarPanel
    Left = 0
    Top = 0
    Width = 938
    Height = 45
    Margins.Left = 5
    Margins.Top = 5
    Margins.Right = 5
    Margins.Bottom = 5
    CustomButtons = <>
    ExplicitLeft = -10
    ExplicitTop = 88
    object ComboBox1: TComboBox
      Left = 512
      Top = 0
      Width = 218
      Height = 33
      Margins.Left = 5
      Margins.Top = 5
      Margins.Right = 5
      Margins.Bottom = 5
      DoubleBuffered = True
      ParentDoubleBuffered = False
      TabOrder = 0
      Text = 'ComboBox1'
    end
  end
  object MainMenu1: TMainMenu
    Left = 261
    Top = 256
    object File1: TMenuItem
      Caption = 'File'
      object File2: TMenuItem
        Caption = 'Exit'
      end
    end
  end
end

这是表单代码,不是真正的代码,因为还没有。

unit CustomTitleBarTestMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.StdCtrls,
  Vcl.TitleBarCtrls;

type
  TForm1 = class(TForm)
    TitleBarPanel1: TTitleBarPanel;
    ComboBox1: TComboBox;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    File2: TMenuItem;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.

如何让 MainMenu 显示在正确的位置?这是屏幕截图 打开应用程序时

按 Alt 一次后

随后按 Alt 后

在您按下 Alt 之前,菜单项没有响应。每次要访问菜单时都必须这样做。

顶部图像在开头,下一个在第一个 Alt,最后一个在后续 alt

如果可能的话,很高兴上传项目。

4

1 回答 1

1

TMainMenu 只是默认窗口功能的一个薄包装器。你不能改变它的位置。但是你可以用 TActionMainMenuBar 替换它。这个可以移到 TTitleBarPanel。

于 2021-12-22T16:00:32.390 回答