使用 CustomTitleBar 将组件添加到标题栏
Adding a component to the Titlebar using CustomTitleBar
我已通过执行以下操作将组合框添加到标题栏:
- 在主窗体上,我将 CustomTitleBar.enabled 设置为 true;
- 将 TitleBarPanel 添加到表单并将 CustomTitleBar.Control 设置为 TitleBarPanel。
- 在 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
这是表单代码,还不是真正的代码 none。
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,最后一个在后续 alts
如果可能的话,很高兴上传项目。
TMainMenu 只是默认 windows 功能的薄包装。你不能改变它的位置。但您可以将其替换为 TActionMainMenuBar。这个可以移到TTitleBarPanel.
我已通过执行以下操作将组合框添加到标题栏:
- 在主窗体上,我将 CustomTitleBar.enabled 设置为 true;
- 将 TitleBarPanel 添加到表单并将 CustomTitleBar.Control 设置为 TitleBarPanel。
- 在 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
这是表单代码,还不是真正的代码 none。
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,最后一个在后续 alts
如果可能的话,很高兴上传项目。
TMainMenu 只是默认 windows 功能的薄包装。你不能改变它的位置。但您可以将其替换为 TActionMainMenuBar。这个可以移到TTitleBarPanel.