zoukankan      html  css  js  c++  java
  • Delphi动态添加控件

    {动态添加导航}
    var
    Panl:Tpanel;
    MainPage,Subpage:TPageControl;
    TabSheet1: TTabSheet;
    ToolBar2: TToolBar;
    Splitter:TSplitter;
    begin
    {创建导航树开始}
     Panl:=Tpanel.Create(self);
     with Panl  do
     begin
        Parent := mainForm;
        Left:= 0 ;
        Top:= 30  ;
        Width:= 185 ;
        Height:= 381 ;
        Align:= alLeft;
        Caption:= ‘Panel1‘;
        TabOrder:= 2;
      end;
      {创建导航树结束}
    
            MainPage:=TPageControl.Create(self);
            with MainPage do
            begin
            Parent := Panl;
                Left := 0;
                Top := 0;
                Width := 235;
                Height := 410;
                ActivePage := 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;
    
      {添加分割条开始}
      Splitter:=TSplitter.Create(self);
      with Splitter  do
      begin
        Parent := mainForm;
        Left := 185;
        Top := 30;
        Height:= 381;
      end;
      {添加分割条结束}
    end;

    delphi 动态创建菜单

    delphi 动态创建菜单
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
    MainMenu:TMainMenu;
    MenuItem:TMenuItem;
    begin
    //创建主菜单对象,并设置主窗口的菜单为MainMenu对象
    MainMenu:=TMainMenu.Create(Self);
    Self.Menu:=MainMenu;
    
    //创建MainMenu主菜单的第一级菜单对象 MainMenu.Items.Add
    MenuItem:=TMenuItem.Create(MainMenu);
    MenuItem.Caption:=‘一级菜单‘;
    MainMenu.Items.Add(MenuItem);
    
    //创建MainMenu主菜单的第二级子菜单对象 MainMenu.Items[0].Add
    MenuItem:=TMenuItem.Create(MainMenu);
    MenuItem.Caption:=‘二级菜单‘;
    MainMenu.Items[0].Add(MenuItem);
    
    //创建MainMenu主菜单的第三级子菜单对象 MainMenu.Items[0].Items[0].Add
    MenuItem:=TMenuItem.Create(MainMenu);
    MenuItem.Caption:=‘三级菜单‘;
    MainMenu.Items[0].Items[0].Add(MenuItem);
    
    // 用Items[0]...这种形式,可以创建 四级、五级直到N级菜单都可以
    
    MenuItem:=TMenuItem.Create(MainMenu);
    MenuItem.Caption:=‘四级菜单‘;
    MainMenu.Items[0].Items[0].Items[0].Add(MenuItem);
    
    end;
    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    vue2.0子组件修改父组件props数据的值
    Visual Studio串口通信与测控应用编程实践
    电梯安装与调试技术
    拾年
    人文生态视野下的城市景观形态研究
    生物真让人惊奇
    神奇生理科学美图大观
    藏在文物里的中国史2 夏商周
    思科UCS服务器统一计算
    Google改变生活
  • 原文地址:https://www.cnblogs.com/jijm123/p/13941454.html
Copyright © 2011-2022 走看看