[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

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.
0
escheider
Asked:
escheider
  • 2
  • 2
1 Solution
 
DanRollinsCommented:
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
0
 
escheiderAuthor Commented:
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.
0
 
DanRollinsCommented:
Look at:
   http://msdn.microsoft.com/netframework/windowsforms/support/wffaq/default.aspx#bc14l0n1
though, as with most .NET stuff, it refers to C# and VB. and it is a bit harder to use the .NET class objects with plain C++ (if you are new to that environment).
   http://msdn.microsoft.com/msdnmag/issues/06/05/MixAndMatch/default.aspx

There is C++ example of how to create a TextBox here:
  http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformstextboxclasstopic.asp

And each of the Control classes show example code in three programming languages.

-- Dan
0
 
escheiderAuthor Commented:
Thank you Dan, this got me on the right path.  I appreciate it.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now