3

I've already posted this as an issue on RRUZ's Vcl Style Utils library on GitHub. However, I thought I could get some help here too.

I'm using VCL Styles to create a Windows 10 user interface, specifically using the "Windows 10 Dark" style. I'm also using the VCL Style Utils to be able to add buttons to the non-client area in the title bar. I'm attempting to completely disregard the form icon and its default functionality in favor of a back button, just like most new Windows 10 apps do.

I'm trying to place a button in the far upper-left corner of the form, using the TNCControls component in Vcl.Styles.NC. However, when I place a button over the form's icon, the button cannot be clicked in the area of the icon. Although I'm able to overlap the icon, clicking in that particular area of the title bar always opens the form's system menu, instead of clicking the button I've placed there.

I do not wish for this menu to pop up when clicking there:

Form System Menu

How I'm currently creating this button:

procedure TfrmTestMain.SetupTitleBar;
var
  B: TNCButton;
begin
  FNCControls:= TNCControls.Create(Self);
  B:= FNCControls.ButtonsList.Add;
  B.Style := TNCButton.TNCButtonStyle.nsTranparent;
  B.BoundsRect := Rect(0, 0, 45, 32);
  B.UseFontAwesome:= True;
  B.Caption := '';
  B.ImageAlignment:= TImageAlignment.iaCenter;
  B.ImageStyle:= TNCButton.TNCImageStyle.isNormal;
  B.ImageIndex:= fa_chevron_left;
end;

What I've tried so far:

  1. Replaced the form's Icon with a completely empty .ico file.

  2. Changing form style to bsSizeToolWin, but the title bar becomes too small, and I lose the minimize / maximize buttons.

  3. Changing form style to bsDialog, but I get the same effect as #2 above, as well as not being able to resize the form.

  4. Made sure button style is nsPushButton, and although it covers up the form icon, clicking the area still clicks the icon, which in turn shows the default system menu.

  5. Following everything in this thread, but the conclusion is that Windows forces you to have this icon.

  6. Removed biSystemMenu from the form's BorderIcons property, but this also removes the default buttons in the top-right of the form, forcing me to place my own system buttons there.

How do do I completely eliminate the form icon and its default functionality in favor of my Windows 10 style back button?

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • 2
    I don't know styles but normally you should be able to turn off system menu in BorderIcons and thus get rid of the icon and the system menu and the caption buttons. – Sertac Akyuz Sep 04 '16 at 00:26
  • I thought turning off `biSystemMenu` in BorderIcons would work, but for some reason in Berlin it also removes the minimize, maximize and close buttons as well. Not sure when this got broken. – Ken White Sep 04 '16 at 01:15
  • @Ken, that's standard api behavior, the caption buttons require ws_sysmenu. – Sertac Akyuz Sep 04 '16 at 01:32
  • .. the loss of the caption buttons shouldn't be an issue for this case, the window is styled anyway - Jerry can use those NCButtons instead. – Sertac Akyuz Sep 04 '16 at 01:34
  • @SertacAkyuz: It's been a while, but I didn't remember it being that way. – Ken White Sep 04 '16 at 01:37

1 Answers1

6

The TNCControls component includes the ShowSystemMenu property. If you set the value to false, then the system menu will be not shown.

Try this

uses
 Vcl.Styles.Utils.Graphics;

procedure TfrmTestMain.FormCreate(Sender: TObject);
begin
 SetupTitleBar;
end;

procedure TfrmTestMain.NCClick(Sender: TObject);
begin
  ShowMessage('Hello');
end;

procedure TfrmTestMain.SetupTitleBar;
var
  B: TNCButton;
begin
  FNCControls:= TNCControls.Create(Self);
  FNCControls.ShowSystemMenu := False; //Disable the system menu.

  B := FNCControls.ButtonsList.Add;
  B.Style := TNCButton.TNCButtonStyle.nsTranparent;
  B.BoundsRect := Rect(0, 0, 45, 32);
  B.UseFontAwesome:= True;
  B.Caption := '';
  B.ImageAlignment:= TImageAlignment.iaCenter;
  B.ImageStyle:= TNCButton.TNCImageStyle.isNormal;
  B.ImageIndex:= fa_chevron_left;
  B.OnClick := NCClick;
end;
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Why TNCControls add a reasonably large gap between the form icon and the caption? I was thinking in case we want to align the buttons on the right side of the screen, next to the minimize, restore and close buttons.... – Alexandre M Nov 05 '20 at 23:05