I have a running calculator on VC++ and don't know how to get an exit button to work. (The X on top right works fine, but want an exit button) I have tried OnOK(); this->CloseWindow(); And other things. Still not managing to close the program from the button. Any tutorials or advice you all can give me?

Is this an MFC program, or what? In Windows Forms CloseWindow() only minimizes the window. You want DestroyWindow().

Edited 5 Years Ago by Ancient Dragon: n/a


Calculator_Dialog C;

Among the things I've tried. Only have that one dialog.

I figured it out somehow, Any chance you can tell me how to group the items in a group box so I can disable them from another button.

You can either do it in the forms designer (drag the groupbox control over and place the other items inside of it), or you can do it programmatically

instantiate a new groupbox
instantiate a new control of whatever type
add it to the groupbox
instantiate a new control of whatever type
add it to the groupbox
add the groupbox to the 'Controls' object of the main form.

Try that out and post back if you can't get it to work (or with any other issues).

Edited 5 Years Ago by jonsca: n/a

Assuming you added 2 textBoxes to a groupbox programmatically and that those were the only 2 controls there

groupBox2 = gcnew GroupBox();
for each (Object^ ctrl in groupBox2->Controls)

(if you had other controls in it, you'd have to know what order they were in, etc).

They can also be addressed as groupBox2->Controls[0] and groupBox2->Controls[1] Since there's no is/as in C++/CLI like there is in C#, I've found that using the Tag property of the control comes in handy. You can assign a string to it (or any object really) and sort your controls based on that.

private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
         Application::Exit();  }

Edited 3 Years Ago by Reverend Jim: Fixed formatting

How did this topic turn from MFC to Windows Forms?

That's on me. I misinterpreted something you said.

I have tried OnOK(); this->CloseWindow()

In Windows Forms CloseWindow()...

as meaning that he was doing Winforms.


At the time I wrote that I didn't know which one it was.

Yes, I know. I was just giving you the stack trace of my brain fart. :) I'm again sorry for steering things the wrong direction... (means I have to bow out, too, as I know next to nothing about MFC)

void CMySecondAppDlg::OnBnClickedButton2()
    // TODO: Add your control notification handler code here

Edited 3 Years Ago by Dani: Formatting fixed

This article has been dead for over six months. Start a new discussion instead.