程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> TMainMenu 類[三] - 手動建立菜單(6) : 更換菜單

TMainMenu 類[三] - 手動建立菜單(6) : 更換菜單

編輯:Delphi

unit Unit1; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, Menus, StdCtrls; 
 
type 
 TForm1 = class(TForm) 
  Button1: TButton; 
  Button2: TButton; 
  procedure FormCreate(Sender: TObject); 
  procedure Button1Click(Sender: TObject); 
  procedure Button2Click(Sender: TObject); 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
var 
 MyMenu1,MyMenu2: TMainMenu; 
 Item: TMenuItem; 
 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
 {建立第一個菜單} 
 MyMenu1 := TMainMenu.Create(Self); 
 MyMenu1.AutoHotkeys := maManual; 
 
 Item := TMenuItem.Create(MyMenu1); 
 Item.Caption := 'AA'; 
 MyMenu1.Items.Add(Item); 
 
 Item := TMenuItem.Create(MyMenu1); 
 Item.Caption := 'BB'; 
 MyMenu1.Items.Add(Item); 
 
 Item := TMenuItem.Create(MyMenu1); 
 Item.Caption := 'CC'; 
 MyMenu1.Items.Add(Item); 
 
 
 {建立第二個菜單} 
 MyMenu2 := TMainMenu.Create(Self); 
 MyMenu2.AutoHotkeys := maManual; 
 
 Item := TMenuItem.Create(MyMenu2); 
 Item.Caption := 'XX'; 
 MyMenu2.Items.Add(Item); 
 
 Item := TMenuItem.Create(MyMenu2); 
 Item.Caption := 'YY'; 
 MyMenu2.Items.Add(Item); 
 
 Item := TMenuItem.Create(MyMenu2); 
 Item.Caption := 'ZZ'; 
 MyMenu2.Items.Add(Item); 
 
 
 Self.Menu := nil; {當前 Form 沒有指向任何一個菜單} 
end; 
 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
 Self.Menu := MyMenu1; {指向第一個菜單} 
end; 
 
 
procedure TForm1.Button2Click(Sender: TObject); 
begin 
 Self.Menu := MyMenu2; {指向第二個菜單} 
end; 
 
end. 

  效果圖:

TMainMenu 類[三] - 手動建立菜單(6) : 更換菜單


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved