• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi动态添加控件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
{动态添加导航}
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;

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[转]DELPHI中千万别直接使用CreateThread ,建议使用BeginThread - marvel775 ...发布时间:2022-07-18
下一篇:
matlab考试重点详解发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap