我已经将它作为an issue on RRUZ's Vcl Style Utils库发布在GitHub上。但是,我认为我也可以在这里得到一些帮助。

我正在使用VCL样式创建Windows 10用户界面,特别是使用“ Windows 10 Dark”样式。我还使用VCL样式实用程序将按钮添加到标题栏中的非客户区域。我试图完全忽略表单图标及其默认功能,而使用后退按钮,就像大多数新的Windows 10应用程序一样。

我正在尝试使用TNCControls中的Vcl.Styles.NC组件在窗体的左上角放置一个按钮。但是,当我在窗体的图标上放置一个按钮时,无法在图标区域中单击该按钮。尽管我可以重叠图标,但是单击标题栏的特定区域始终会打开表单的系统菜单,而不是单击我在此处放置的按钮。

我不希望在单击该菜单时弹出此菜单:

delphi - Vcl样式实用程序-摆脱默认表单图标-LMLPHP

我目前如何创建此按钮:

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;


到目前为止,我已经尝试过:


将表单的“图标”替换为完全空的.ico文件。
将表单样式更改为bsSizeToolWin,但是标题栏变得太小,我失去了“最小化/最大化”按钮。
将表单样式更改为bsDialog,但我得到的效果与上面的#2相同,并且无法调整表单的大小。
确保按钮样式为nsPushButton,尽管它掩盖了表单图标,但单击该区域仍会单击该图标,从而显示默认的系统菜单。
跟随everything in this thread,但是结论是Windows强制您使用此图标。
从窗体的biSystemMenu属性中删除了BorderIcons,但这也删除了窗体右上角的默认按钮,迫使我在此处放置自己的系统按钮。


如何完全取消窗体图标及其默认功能,而使用Windows 10样式的后退按钮?

最佳答案

TNCControls组件包括ShowSystemMenu属性。如果将值设置为false,则不会显示系统菜单。

尝试这个

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;

10-07 19:09
查看更多