?
Solved

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

Posted on 2008-06-13
5
Medium Priority
?
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

719 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