使用两种形式时出现问题 [英] Problem while using Two Forms

查看:41
本文介绍了使用两种形式时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何问这个问题.问题在下面给出.

i don't know how to ask this question. problem is given below.

我正在使用一个主窗体和许多子窗体,但没有使用MDI窗体.主窗体包含5个按钮和一个面板.每个按钮都会调用一个表格在该面板内(作为父级).在该子窗体中,一个窗体(Sub3)包含TMainMenu组件.通过单击按钮进行调用时,每个窗体都可以正常工作,但是在调用窗体(Sub3)时,TMainMenu不可见.我不知道如何使它可见.请任何人帮助我.

I'm using One Main form and many sub forms but not MDI Forms. Main form Contains 5 Buttons and a Panel. each button will call a form inside that Panel(as Parent). in that sub forms, one form(Sub3) contain TMainMenu component. every form is working correctly while calling by clicking the buttons but, while calling the form(Sub3) the TMainMenu is not in visible. i don't know how to bring it visible. Please help me any one.

预先感谢.

感谢&问候

Yuvaraj

推荐答案

每种形式上只能有一个MainMenu.虽然一个应用程序中可以有多个窗体,每个窗体都有自己的MainMenu,但如果在另一个窗体中显示一个窗体,则只有外部"窗体的主菜单可见.

You can only have one MainMenu on each form. While you can have multiple forms in an app each with its own MainMenu, if you show one form within another form, only the mainmenu of the "outer" form will be visible.

当您将一个表单与另一个表单父"化(在formA上将formB显示为组件")时,您必须像上面提到的@skamradt那样合并菜单本身.

When you "reparent" a form to another (show formB as a "component" on formA), then you have to merge the menu's yourself as @skamradt already mentioned.

为此,只需让您的按钮使用"SwitchToForm"功能,如:

To do so, simply have your buttons use a "SwitchToForm" function like:

type
  TMain_Form
  ...
  private
    FCurrentForm: TForm;
    procedure SwitchToForm(showForm: TForm);
  ...
  end;

procedure TMain_Form.SwitchToForm(showForm: TForm);
begin
  if (FCurrentForm <> nil) and (FCurrentForm.Name = showForm.Name) then begin
    // Naught to do
  end else begin
    // If a form is currently showing, hide it and if it has a menu, unmerge that 
    if FCurrentForm <> nil then 
    begin
      FCurrentForm.Hide;
      if Assigned(FCurrentForm.Menu) then 
      begin
        MainMenu.UnMerge(FCurrentForm.Menu);
      end;
    end;

    // Set the current form to the one passed in and re-parent that to the main form
    // If the form has a menu, merge that with the main menu of the main form and then
    // show it.
    FCurrentForm := showForm;
    with FCurrentForm do begin
      Parent := self;
      Align := alClient;
      BorderIcons := [];
      BorderStyle := bsNone;
    end;
    if Assigned(FCurrentForm.Menu) then begin
      MainMenu.Merge(FCurrentForm.Menu);
    end;
    FCurrentForm.Show;
  end;
end;

在此示例中:表单是主表单本身的父级,但是您当然也可以将表单作为主面板上的面板或其他容器的父级.

In this example: the form is parented to the main form itself, but you could of course also parent the forms to a panel or some other container on the main form.

这篇关于使用两种形式时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆