{ Dynamically add navigation } var Panl: TPanel; the MainPage, Subpage: TPageControl; TabSheet1: TTabSheet; ToolBar2: TToolBar; Splitter: TSplitter; the begin { create the navigation tree begins } Panl: = TPanel. The Create (Self); with Panl do the begin the Parent : = mainForm; Left: = 0 ; Top: = 30 ; the Width: = 185 ; the Height: = 381 ; the Align: = alLeft; The Caption: = ' Panel1 ' ; the TabOrder: = 2 ; End ; { create the navigation tree ends } the MainPage: = TPageControl. The Create (Self); with the MainPage do the begin the Parent: = Panl; Left: = 0 ; Top: = 0 ; the Width : = 235 ; the Height: = 410 ; ActivePage of: = TabSheet1; Align := alClient; BiDiMode := bdLeftToRight; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Name := 'MS Sans Serif'; Font.Style := []; MultiLine := True; ParentBiDiMode := False; ParentFont := False; TabOrder := 0; TabPosition := tpLeft; end; TabSheet1:=TTabSheet.Create(self); TabSheet1.Parent := MainPage; TabSheet1.Caption := '树形导航'; ToolBar2:=TToolBar.Create(self); with ToolBar2 do begin Parent :=TabSheet1; Left := 0; Top := 0; Width := 207; Height := 30; ButtonHeight := 28; ButtonWidth := 29; Caption := 'ToolBar2'; EdgeInner := esNone; EdgeOuter := esNone; Flat := True; Images := ImageList1; TabOrder := 0; TabStop := True; Wrapable: = False; End ; { add splitter Start } Splitter: . = TSplitter the Create (Self); with Splitter do the begin the Parent: = mainForm; Left: = 185 ; Top: = 30 ; the Height: = 381 ; end ; { add splitter end } end ;
delphi dynamically created menus
delphi dynamically created menus Procedure TForm1.Button1Click (Sender: TObject); var MainMenu: exposed by the TMainMenu; the MenuItem: TMenuItem; the begin // Create the main menu object, and set the main window menu objects MainMenu MainMenu: = exposed by the TMainMenu. the Create (Self); Self.Menu: = MainMenu; // Create MainMenu first level menu of the main menu objects MainMenu.Items.Add the MenuItem: = TMenuItem. the Create (MainMenu); MenuItem.Caption: = ' a menu ' ; MainMenu.Items.Add (the MenuItem); // Create the main menu MainMenu second submenu objects MainMenu.Items [0] .Add the MenuItem: = TMenuItem. the Create = (MainMenu); MenuItem.Caption:' Secondary menu ' ; MainMenu.Items [ 0 ] .Add (the MenuItem); // Create the main menu MainMenu third level sub-menu objects MainMenu.Items [0] .Items [0] .Add the MenuItem: = TMenuItem. The Create (a MainMenu); MenuItem.Caption: = ' third level ' ; MainMenu.Items [ 0 ] .Items [ 0 ] .Add (the MenuItem); // with Items [0] ... in this form, can create four , up to five N-level menus can be the MenuItem: = TMenuItem. the Create (a MainMenu); MenuItem.Caption: = ' four menu ' ; MainMenu.Items [ 0 ] .Items [ 0 ] .Items [0].Add(MenuItem); end;