Link to home
Start Free TrialLog in
Avatar of jrb1204
jrb1204

asked on

I need to have a form without the red x close button

I need to remove the red x close button on a form. II will handle the close with a button on the form.
I want to keep all other functionality such as minimize, maximize and caption.
 I have tried EnableMenuItem(AppSysMenu,SC_CLOSE,MF_BYCOMMAND or MF_GRAYED) but this only grays it out.  Any suggestions ?
Avatar of SteveBay
SteveBay
Flag of United States of America image

look at the BorderIcons property of the Form.
You will want to set biSystemMenu = False;
or at runtime you can do this:


procedure TForm1.Button1Click(Sender: TObject);
begin
     Self.BorderIcons := Self.BorderIcons - [biSystemMenu];
end;

Open in new window

I just re-read your question and I see that you wish to keep minimize, maximize and caption. That will require some more effort. I'll have to do some looking...
I think this is close to what you want.
procedure TForm1.FormCreate(Sender: TObject);
var  h : hMenu;
     i : Integer;
begin
     h := GetSystemMenu(Handle, False );
     for i := GetMenuItemCount(h)- 1 downto 0 do
          if GetMenuItemID(h,i) = SC_CLOSE then
                RemoveMenu(h,i,MF_BYPOSITION);
end;

Open in new window

Avatar of jrb1204
jrb1204

ASKER

The solution from your last post works to disable the close [x]  icon but what I was looking for was a way to hide it.
ASKER CERTIFIED SOLUTION
Avatar of SteveBay
SteveBay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial