Link to home
Start Free TrialLog in
Avatar of escheider
escheider

asked on

Creating controls at runtime

Good afternoon experts:

I'm trying to locate some documentation on creating controls at runtime without much sucess.  I have a combobox that lists the different types of controls, and when the user selects a control in the combo box, I'd like to create it.  

Could you provide an example of how to create a control, like a radio button or textbox, during runtime?

I'm using C++.NET 2005

Any help is appreciated.
Avatar of DanRollins
DanRollins
Flag of United States of America image

If you use MFC (and most vc++ programmers do) then check the documentation for objects such as
  CComboBoc
  CEditCtrl
  CButton
  ... etc...  
See http://msdn.microsoft.com/library/en-us/vclib/html/vclrfMFCClassListing.asp

Each of these object has a "Create" memeber function.  You can specify various "style" options in that call as well as the on-screen location to display the control.  For instance, in a dialog box, you could use code like:

   static CButton myBtn;
   myBtn.Create( "My button", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), this, 1);

and a button would appear in the dialog.  There would be additional steps to take if you need to be able to take action when the button gets clicked (etc.) but the Create function is what you need to use to create it in the first place.

-- Dan
Avatar of escheider
escheider

ASKER

I'm fairly new to VC++.NET, so I'm using Windows Forms, not MFC, and I'm finding a lack of information on the subject.
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Dan, this got me on the right path.  I appreciate it.