Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-13
5
Medium Priority
?
380 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 150 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

971 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