Solved

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

Posted on 2008-06-13
5
374 Views
Last Modified: 2010-04-05
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 ?
0
Comment
Question by:jrb1204
  • 4
5 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 21781041
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

0
 
LVL 14

Expert Comment

by:SteveBay
ID: 21781068
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...
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 21781162
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

0
 

Author Comment

by:jrb1204
ID: 21781502
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.
0
 
LVL 14

Accepted Solution

by:
SteveBay earned 50 total points
ID: 21781678
Everywhere I've looked this is roughly the technique I have found. I suppose that it is posible to hide the [X] and not the the other menu buttons but I cannot find an example.
Why do wish to hide it? Are you trying to control the program close process? If so you should be using the the TForm.OnCloseQuery event rather than changing a long standing and well accepted Windows convention.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can Viruses spread while transferring Binary data with Winsock 2 79
LAN or WAN ? 11 92
Graphics32 under Delphi 10.1 Berlin 2 69
enhance the following code 3 32
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question