📄 chapt12.htm
字号:
<html><head><title>第十二章 菜单的创建与管理</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body bgcolor="#00000" text="#00cc66"><p align="center"><b><font color="#FF9999" size="4">第十二章 菜单的创建与管理 </font></b></p><p><b> 12.5.1 增加项目到菜单</b><br> 动态增加菜单项可以使用TMenuItem对象的Add函数或Insert函数。使用Add对象函数,在当前菜单的尾部增加一个菜单项,函数原型为:<br> procedure Add(Item: TMenuItem);<br> 这里,Item指定要增加的菜单项。下例是当用户如单击Button1按钮时,增加一个新菜单项到File菜单的尾部的过程:<br> procedure Form1.Button1Click(Sender: TSender);<br> var NewItem: TMenuItem; <br> begin <br> NewItem := TMenuItem.Create(Self);<br> NewItem.Caption := 'New item'; <br> File.Add(NewItem);<br> end;<br> 使用Insert对象函数在一个指定菜单项前插入一个菜单项,其原型为:<br> procedure Insert(Index: Integer; Item: TMenuItem);<br> 这里Index指定插入的菜单项序号(从0开始数),Item是要插入的菜单项。下例是当用户如单击Button1按钮时,插入一个新菜单项到WindowMenu菜单第一条菜单项之后的过程:<br> procedure TForm1.Button1Click(Sender: TObject);<br> var NewItem: TMenuItem;<br> begin <br> NewItem := TMenuItem.Create(WindowMenu); {Creates the new menu item} <br> NewItem.Caption := 'My Menu Command'; {Caption for the new menu item} <br> WindowMenu.Insert(1, NewItem); {Inserts the new menu item}<br> end;<br> <b>12.5.2 删除菜单项</b><br> 要删除一个菜单项,可以使用TMenuItem对象的Delete函数。其函数原型为: <br> procedure Delete(Index: Integer);<br> 这里,Index指定要删除项目的序号(从0开始数)。比如,要删除WindowMenu菜单下的第2条菜单,可以编写如下语句:<br> WindowMenu.Delete(1); </p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -