我通過執行以下操作向標題欄添加了一個組合框:
- 在主表單上,我將 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
這是表單代碼,不是真正的代碼,因為還沒有。
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 之前,選單項沒有回應。每次要訪問選單時都必須這樣做。
The top image is on Opening, the next on first Alt, the last on subsequent alts
Happy to upload the project if that is possible.
uj5u.com熱心網友回復:
TMainMenu 只是一個圍繞默認視窗功能的薄包裝。你不能改變它的位置。但是你可以用 TActionMainMenuBar 替換它。這個可以移動到 TTitleBarPanel。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/392903.html
標籤:delphi windows-11
上一篇:RADStudio:無法決議單元名稱“pFIBDatabase”(安裝包)
下一篇:TEdgeBrowser-OnNewWindowRequested-在另一個TEdgeBrowser中打開新視窗
