delphi - 如何在 TMainmenu 的项目前打勾?

delphi - how do I make a tick in front of a TMainmenu's item?

我想在单击 TMainMenu 项目前打勾或 "x"。有什么办法吗?

假设菜单项名为 mnuSetting,只需在其 OnClick 处理程序中写入:

procedure TForm1.mnuSettingClick(Sender: TObject);
begin
  mnuSetting.Checked := not mnuSetting.Checked;
end;

启用菜单项的 AutoCheck 属性。链接参考将其描述为:

AutoCheck

Indicates whether the menu item's checked state toggles automatically when the item is clicked.

When AutoCheck is true, then every time the menu item is clicked, the value of the Checked property toggles automatically before the OnClick event occurs. When AutoCheck is false, the application must explicitly set the value of the Checked property (for example, in an OnClick event handler).