Delphi菜單組件TMainMenu使用方法詳解
本文為大家分享了菜單組件TMainMenud的使用方法,供大家參考,具體內(nèi)容如下
菜單組件TMainMenu
創(chuàng)建菜單雙擊TmenuMain,單擊Caption就可以添加一個菜單項
菜單中添加分割線只需加“-”就可以添加一個分割線
級聯(lián)菜單的設(shè)計
單擊鼠標(biāo)右鍵彈出菜單中選擇Create Submenu菜單項
單選功能設(shè)計
要在設(shè)計的菜單項目中選擇RadioItem屬性為True,Checked屬性為True
復(fù)選功能的設(shè)計
在設(shè)計菜單項目中選擇RadioItem屬性為False,Checked屬性為True
動態(tài)創(chuàng)建菜單
源代碼如下
procedure TForm1.Button1Click(Sender: TObject); var MainMenu: TMainMenu; MenuItem: TMenuItem; begin //主菜單創(chuàng)建 MainMenu:=TMainMenu.Create(self); Self.Menu:=MainMenu; //文件菜單創(chuàng)建 MenuItem:= TMenuItem.Create(MainMenu); MenuItem.Caption:='文件'; MainMenu.Items.Add(MenuItem); //新建子菜單創(chuàng)建 MenuItem:=TMenuItem.Create(MainMenu); MenuItem.Caption:='新建'; MainMenu.Items[0].Add(MenuItem); //子菜單中的子菜單創(chuàng)建 MenuItem:= TMenuItem.Create(MainMenu); MenuItem.Caption:='打開'; MainMenu.Items[0].Items[0].Add(MenuItem); MenuItem:= TMenuItem.Create(MainMenu); MenuItem.Caption:='保存'; MainMenu.Items[0].Items[0].Add(MenuItem); end; end.
為主菜單添加圖標(biāo)
為菜單添加圖標(biāo),首先用TImagaList組件為菜單指定好圖標(biāo),將菜單中的Images屬性設(shè)為ImageList1,然后選擇要添加的圖標(biāo)索引。如圖所示:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Delphi實現(xiàn)樹型結(jié)構(gòu)具體實例
這篇文章介紹了Delphi實現(xiàn)樹型結(jié)構(gòu)具體實例,有需要的朋友可以參考一下2013-10-10Delphi實現(xiàn)讀取系統(tǒng)時間與日期完整實例
這篇文章主要介紹了Delphi實現(xiàn)讀取系統(tǒng)時間與日期完整實例,需要的朋友可以參考下2014-07-07