943,929 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3142
  • C++ RSS
May 12th, 2009
0

Disable Close button on form

Expand Post »
How would it be possible to disable the closebutton(X) in the upper right corner of the form.
I dont want to use this property because it takes the minimize and maximize button away also.
C++ Syntax (Toggle Plain Text)
  1. ControlBox = false;

The only thing I will need on the form is the minimizebutton.
I can find separate properties for the minimizebutton and maximizebutton but not for the (X) button.
Last edited by Lukezzz; May 12th, 2009 at 10:09 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Posting Whiz in Training
Lukezzz is offline Offline
268 posts
since Mar 2008
May 12th, 2009
0

Re: Disable Close button on form

[Warning: This is coming from a Java programmer with no C++ experience]

Assuming that clicking 'X' generates an event, and C++ has method overriding - override the method that closes the window when the user clicks 'X', and do nothing in that method. That way, nothing will happen when the 'X' is clicked.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
May 13th, 2009
0

Re: Disable Close button on form

The problem is that I have put "Exit" in the File menu that will be used to close the window and the application like:
C++ Syntax (Toggle Plain Text)
  1. this->Close();

So I cant if that is possible to not close the form in that event.

I still need to disable or remove the close(X) from the form in somehow.


[Warning: This is coming from a Java programmer with no C++ experience]

Assuming that clicking 'X' generates an event, and C++ has method overriding - override the method that closes the window when the user clicks 'X', and do nothing in that method. That way, nothing will happen when the 'X' is clicked.
Reputation Points: 10
Solved Threads: 1
Posting Whiz in Training
Lukezzz is offline Offline
268 posts
since Mar 2008
May 13th, 2009
0

Re: Disable Close button on form

Give us a little chance and tell us what GUI you are using?
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
May 13th, 2009
0

Re: Disable Close button on form

Yes ofcourse, I forgot to tell this.

I use Visual C++ 2008 Express Edition. I am googling around but I have problem to find a direct solution for this.


Click to Expand / Collapse  Quote originally posted by jencas ...
Give us a little chance and tell us what GUI you are using?
Reputation Points: 10
Solved Threads: 1
Posting Whiz in Training
Lukezzz is offline Offline
268 posts
since Mar 2008
May 13th, 2009
0

Re: Disable Close button on form

c++ Syntax (Toggle Plain Text)
  1.  
  2. // extra variable
  3. Boolean can_exit;
  4.  
  5. // form closing
  6. if(!can_exit)
  7. e->Cancel::set(true);
  8.  
  9. // button exit click
  10. can_exit = true;
  11.  
  12. this->Close();
  13.  
  14. // form load
  15. can_exit = false;
hope that helps..
Last edited by cikara21; May 13th, 2009 at 12:46 pm.
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
May 13th, 2009
0

Re: Disable Close button on form

It seems to work almost, I have to ask here.
I have succeded to put this as a global variable:
bool can_exit;
In the closing event of the form, I have put this code:
if(!can_exit)
   e->Cancel::set(true);
In the Load event of the form, I have put this code:
can_exit = false;

But I dont understand where to put this code:
// button exit click
can_exit = true;

I have never found an event for the close(x) button but perheps there is one ? I wonder if that code will be put in that event in that case.

However if I put the other code in place, nothing happens when I click the close(X) button wich is perfect.
However when I press a button on the form that tries to close the form(below code), nothing happens but perheps that has to do with the code that I wonder where to put:
C++ Syntax (Toggle Plain Text)
  1. this->Close();

this->Close();
Click to Expand / Collapse  Quote originally posted by cikara21 ...
c++ Syntax (Toggle Plain Text)
  1.  
  2. // extra variable
  3. Boolean can_exit;
  4.  
  5. // form closing
  6. if(!can_exit)
  7. e->Cancel::set(true);
  8.  
  9. // button exit click
  10. can_exit = true;
  11.  
  12. this->Close();
  13.  
  14. // form load
  15. can_exit = false;
hope that helps..
Last edited by Lukezzz; May 13th, 2009 at 3:31 pm.
Reputation Points: 10
Solved Threads: 1
Posting Whiz in Training
Lukezzz is offline Offline
268 posts
since Mar 2008
May 13th, 2009
0

Re: Disable Close button on form

I just understood that I will put that code in the event for the button that will close the form:

Many thanks for this help...

C++ Syntax (Toggle Plain Text)
  1. // button exit click
  2. can_exit = true;
Reputation Points: 10
Solved Threads: 1
Posting Whiz in Training
Lukezzz is offline Offline
268 posts
since Mar 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: print data from a binary file
Next Thread in C++ Forum Timeline: cin.getline() question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC