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.

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.

Recommended Answers

All 7 Replies

[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.

The problem is that I have put "Exit" in the File menu that will be used to close the window and the application like:

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.

Member Avatar for jencas

Give us a little chance and tell us what GUI you are using?

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.

Give us a little chance and tell us what GUI you are using?

// extra variable
Boolean can_exit;

// form closing
if(!can_exit)
   e->Cancel::set(true);

// button exit click
can_exit = true;

this->Close();

// form load
can_exit = false;

hope that helps..

It seems to work almost, I have to ask here.
I have succeded to put this as a global variable:

[B]bool can_exit;[/B]

In the closing event of the form, I have put this code:

[B]if(!can_exit)
   e->Cancel::set(true);[/B]

In the Load event of the form, I have put this code:

[B]can_exit = false;[/B]

But I dont understand where to put this code:

[I]// button exit click
can_exit = true;[/I]

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:

this->Close();

this->Close();

// extra variable
Boolean can_exit;

// form closing
if(!can_exit)
   e->Cancel::set(true);

// button exit click
can_exit = true;

this->Close();

// form load
can_exit = false;

hope that helps..

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...

// button exit click
can_exit = true;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.