Reputation: 4102
I want to remove or disable the buttons inside the main menu, that controls the child form (minimize, restore), of my application.
The application should look like a "browser", where the MDI child forms must stay maximized all the time.
I alreday tried to disable they, by setting
BoderIcons := [biSystemMenu];
But I got this:
I alreday tried to disable the menu commands at the WM_INITMENU message, but without success:
procedure WMInitMenu(var Message: TWMInitMenu); message WM_INITMENU;
procedure TMyMDIChildForm.WMInitMenu(var Message: TWMInitMenu);
begin
inherited;
EnableMenuItem(Message.Menu, SC_MAXIMIZE, MF_BYCOMMAND or MF_GRAYED);
EnableMenuItem(Message.Menu, SC_MINIMIZE, MF_BYCOMMAND or MF_GRAYED);
end;
I'm using:
Upvotes: 2
Views: 3338
Reputation: 256
Somehow the accepted answer does not work me. This works for me instead: MDIChildForm.BorderIcons := MDIChildForm.BorderIcons - [biSystemMenu];
Upvotes: 0
Reputation: 4102
I solved by intercepting the WM_COMMAND at the MainForm as the follow code shows:
type
TMDIMainForm = class(TForm)
protected
procedure WMCommand(var Message: TWMCommand); message WM_COMMAND;
end;
implementation
procedure TMDIMainForm.WMCommand(var Message: TWMCommand);
begin
case Message.ItemID of
SC_CLOSE, SC_MINIMIZE, SC_RESTORE, SC_MAXIMIZE:
begin
Message.Result := 0;
Exit;
end;
else
inherited;
end;
end;
At the child forms, I simple placed this:
procedure TMDIChild.OnCreate(Sender: TObject);
begin
WindowState := wsMaximized;
end;
Now my MDI childs stays maximized and the user isn't able to restore or minimize than.
Upvotes: 2
Reputation: 487
MDI is exactly a mechanism for having a from (child) floating inside another form (parent). Can't see the point having it permanently maximized.
If you whant is to separate code and have it in other unit you can use frame (that can be inserted in design time or in runtime) or forms (using something the following code)
procedure TParentForm.FormCreate(ASender: TObject);
begin
FEmbeddedForm := TEmbeddedForm.Create(self);
FEmbeddedForm.Parent := Panel1;
FEmbeddedForm.Align := alClient;
FEmbeddedForm.BorderStyle := bsNone;
FEmbeddedForm.Visible := True;
end;
Upvotes: 1
Reputation: 163247
You're going to end up fighting just about everything that makes MDI what it is. Instead of using MDI, consider using frames. Design a TFrame
descendant to represent one screen of your UI. You can put instances on a TPageControl
to help organize them. (Set each page's TabVisible
property to false if you want to provide your own method of navigating between screens.)
Upvotes: 2