Delphi develops different form title bars: TTitleBarPanel

Table of contents

Use of TTitleBarPanel

Advanced use of TTitleBarPanel

1. Set the height and color of the title bar

 2. Buttons such as closing the personalized title bar


When we use Delphi to develop programs, the title bar of the form is generally the standard windows title bar, which includes: program icon, title, minimize, maximize, close, help and other buttons.

 However, sometimes we can see that the title bar of other people's programs is very different and feels very novel, for example:

 On the surface, the title bar of the platform key tool program developed by Alipay seems to be the same as our Delphi standard title bar, but in fact there is a big difference. Currently you see the difference at least:

  1. The height of the title bar is different, the height of the standard Delphi title bar cannot be adjusted normally, it is a fixed value;
  2. The color of the title bar is different, and there is no way to adjust the color of the standard Delphi title bar.
  3. The minimize button and close button icons are not standard button icons, but custom ones.

In fact, there are many differences, such as whether we can place other controls on the title bar, such as TButton, TLabel, TPanel, etc. Of course it is possible, this is the TTitleBarPanel control.

TTitleBarPanel is a Delphi native control, introduced in Delphi 10.4. Before the introduction of the TTitleBarPanel control, we generally need the support of third-party controls to personalize the title.

TTitleBarPanel allows placing controls in the title bar area of ​​a VCL form. It provides the following support for the implementation of CustomTitleBar (this is a property of Form): 

  1. Supports placement of controls (visualization) at design time.
  2. Centrally manage controls in the title bar.
  3. Support custom drawing OnPaint.
  4. Allows customizing native title bars of VCL forms, similar to Windows Explorer, Google Chrome or other applications. This feature is supported on Windows 7 and later.

Use of TTitleBarPanel

Notice:

        To paint or draw anything on the title bar to customize the title bar, you must place a TTitleBarPanel control on the form and set the form's CustomTitleBar.Control property to it.

first step:

        Place a TTitleBarPanel control on the form (the control is on the windows10 panel)

 Step two:

  1.  Set the form's CustomTitleBar.Control to TitleBarPanel1.
  2.  Set the form's CustomTitleBar.Enabled to True

 third step:

        At this point, other controls can be placed on TitleBarPanel1.

 

Advanced use of TTitleBarPanel

The title bar of a form can be fully customized by modifying the properties in the form's CustomTitleBar:

  1. CustomTitleBar.SystemHeight: Indicates whether the title bar uses the system default height, and the default is to use the system value;
  2. CustomTitleBar.SystemColors: Indicates whether to use the system default title bar color, the default is to use the system value;
  3. CustomTitleBar.SystemButtons: Whether to use the buttons in the upper right corner of the system;
  4. CustomTitleBar.ShowIcon: Whether to display the long icon in the upper left corner, the default is to display;
  5. CustomTitleBar.ShowCaption: indicates whether to display the window title content.

By setting the above properties and modifying the Form properties, a very ideal form title bar can be realized.

Special attention: the performance effect of setting the absolute value of the parameter is different under ultra-high resolution and high-definition!

1. Set the height and color of the title bar

  with Self do
   begin
      CustomTitleBar.SystemHeight := False;
      CustomTitleBar.Height       :=30;
      CustomTitleBar.SystemColors := False;
      CustomTitleBar.BackgroundColor := clred;
    end;

 2. Buttons such as closing the personalized title bar

  1. CustomTitleBar.SystemButtons := False; //Actually, it seems that this property does not need to be set
  2. Turn off Form.BorderIcons:
  3. Then place SpeedButton or picture in TitleBarPanel1 to realize appearance customization and function simulation.

For example:

Pitfalls to watch out for:

Under Ultra HD (4K) and HD (2K), many controls of Delphi behave differently, and the same is true for the TitleBarPanel control. Everyone should pay attention when using it. With the popularity of ultra-high-definition monitors, when developing Delphi programs , be sure to carry out relevant UI compatibility tests. The compatibility bin here is not unusable, but the UI interface displayed is inconsistent, which is not the original expected result.

Guess you like

Origin blog.csdn.net/sensor_WU/article/details/132053943