给动态创建的TREE和MAINMENU关联点击事件

本文介绍了一种使用递归方法遍历菜单项的方法,并实现了菜单项点击时打开相应子窗体的功能。同时提供了几种常见菜单选项对应的子窗体处理逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用递归方法遍历MAINMENU的所有菜单项

procedure   TFormMain.BLMenu;
    procedure   GetItems(AItem:TMenuItem);
    var
        I:integer;
    begin
        AItem.OnClick := MenuTreeClick;      //菜单项关联点击事件
        for   I:=0   to   AItem.Count-1   do   begin
            GEtItems(AItem.Items[I]);
        end;
    end;
var
    I:integer;
begin
    for   I:=0   to   MainMenu1.Items.Count-1   do   begin
        GetItems(MainMenu1.Items.Items[I]);
    end;
end;

 

公用的点击事件处理方法

procedure TFormMain.MenuTreeClick(Sender: TObject);
begin
  if Sender is TTreeView then     // 通过SENDER来判断是点击了菜单项还是树的节点
    todo(TTreeView(Sender).Selected.Text)
  else if Sender is TMenuItem then
    todo(StripHotkey(TMenuItem(Sender).Caption));
end;

 

公用打开子窗体方法

procedure TFormMain.openForm(AFormClass: TFormClass; var aForm: TForm;
  aOwner: TWinControl);
begin
  if aOwner = nil then Exit;
  if aForm = nil then
    aForm := AFormClass.Create(aOwner);
  with aForm do
  begin
    ManualDock(aOwner);
    WindowState := wsMaximized;
    Align := alClient;
    Show;
  end;
end;

 

点击事件的处理方法

procedure TFormMain.todo(const aCaption: string);
begin
  if Pos('数据字典', acaption) <> 0 then begin
    if ActiveExistTabsheet('数据字典') then Exit;
    openForm(TformDictionary, tform(formdictionary), GetTabSheet('数据字典'));
  end else if Pos('系统菜单', aCaption) <> 0 then begin
    if ActiveExistTabsheet('系统菜单') then Exit;
    openForm(Tformmenu, tform(formMenu), GetTabSheet('系统菜单'));
  end else if Pos('货品类别管理', aCaption) <> 0 then begin
    if ActiveExistTabsheet('货品类别管理') then Exit;
    openForm(TformCategory, tform(formCategory), GetTabSheet('货品类别管理'));
  end else if Pos('操作员管理', aCaption) <> 0 then begin
    if ActiveExistTabsheet('操作员管理') then Exit;
    openForm(TFormOperator, tform(FormOperator), GetTabSheet('操作员管理'));
  end;                     
end;

转载于:https://www.cnblogs.com/hnxxcxg/archive/2010/08/14/2940683.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值