Home > Blockchain >  Adding a component to the Titlebar using CustomTitleBar
Adding a component to the Titlebar using CustomTitleBar

Time:12-24

I have added a ComboBox to the Title bar by doing the following:

  1. On the Main form I set CustomTitleBar.enabled to true;
  2. Add a TitleBarPanel to the form and set the CustomTitleBar.Control to the TitleBarPanel.
  3. Place a ComboBox on the TitleBarPanel and align it appropriately.

This works well when I run it but if I add a MainMenu to the form the menu appears under the TitleBarPanel. I have trawled the web for solutions but without success. Is there something else which needs to happen before the MainMenu displays properly.

This is my form:

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

This is the forms code, not really code as there is none yet.

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.

How can I get the MainMenu to display in the correct place? here are the screenshots On opening App

After pressing Alt once

After subsequent presses of Alt

The menu items are unresponsive until you hit Alt. You have to do this every time you want to access the menu.

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.

CodePudding user response:

TMainMenu is just a thin wraper around default windows functionality. You can't change its position. But you can replace it with TActionMainMenuBar. This one can be moved to TTitleBarPanel.

  • Related