tags:

views:

107

answers:

3

Hi

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

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.

Thanks in Advance.

Thanks & Regards,

Yuvaraj

A: 

You can use the TMainMenu.Merge and TMainMenu.Unmerge to merge/unmerge the sub-form menu with the main form menu. In your "OnActivate" for each of the child forms, I would send a custom message to the main form that would unmerge any menus from another form (which might already not be set) and merge the menu for the current form.

skamradt
Thanks to you all for the response once again thanks... by Yuvaraj
A: 

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.

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.

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.

Marjan Venema
Hi, Main Form Not containing then MainMenu control. Only subform contains the MainMenu Control.
Well, that's not going to work then is it. Only the "outer" form's main menu will be shown by the vcl as I already mentioned. So give it one with for example just a "help" menu. Possibly even only show it when a menu is merged into it from a subform, but I don't whether a main menu responds well to having its visible property changed.
Marjan Venema
+1  A: 

try to check on your form(sub3) borderstyle must not be bsDialog or else menu will not shown up. check every form that has a TmainMenu. see object inspector form2>borderstyle do not use bsDialog. i got same problem before.

XBasic3000