How to create button on visual C++ Form
I am quite new to programming and visual c++. and I have requirement to create form using form design, and on that form I wish to create two button One "Submit" and "Cancel" on the same form, which should opens up a new form and then later close that form and return to my original form.
Re: How to create button on visual C++ Form
Open the first form in Visual Studio Designer and double-click on your button. The Click handler will be opened. Then type a fragment like this:
namespace Form1 {
using namespace System;
using namespace System:: ComponentModel;
using namespace System:: Collections;
using namespace System:: Windows::Forms;
using namespace System:: Data;
using namespace System:: Drawing;
MySecondForm ^ form = gcnew MySecondForm;
form->ShowDialog();
}
Re: How to create button on visual C++ Form
There are a lot more than 10. but if you want 10, just off the top of my head, would be picturebox, listbox, combobox, textbox, label, button, checkbox, optionbutton (or radio button), tabstrip, timer. It is not obvious how to add additional buttons. Perhaps they are instances of CButton. But there are no examples. CButton is defined in afxwin.h (MFC) and derived from CWnd. A text property is defined under CWnd - use GetWindowText & SetWindowText. There does not appear to be a property for the button text. There are many more, those are just the first 10 I thought of.
Source(s):
Open up C++ and look at the toolbar on your left. That has all the basic controls on it.
Re: How to create button on visual C++ Form
The buttons appear to be defined in *.rc (resource file). It will be called when you click on the Button when the application is running. The code instantiates the new window and shows it. Of course MySecondForm has to be replaced by your Window/Form class. Notice also that *.rc is the name of the displayed form. You would think that there would be a way to add another mfc component to the form.