Replace one control with another based on selection

usererror

New member
Joined
Feb 12, 2012
Messages
2
Programming Experience
Beginner
On my form I have two radio buttons. One for CDs and one for books. If I select CDs I have a group box that changes visible = true and I have txt boxes there I want to input. If I select books I want the groupbox to remain visible = false and in its place a text box to appear. How would I do this? I know I can just overlap the controls but that looks hideous in designer. Any suggestions would be awesome thanks!
 
I think that "hideous" is a bit of an exaggeration but, regardless, who cares what it looks like in the designer? It is still easy to work with and it looks right at run time, which is what matters. You could create and destroy the controls at run time but then you won't see anything at design time. You could also change the Location of the controls at run time but will that really make things better at design time? If it was me, I'd be doing exactly what you're doing right now.
 
If it's included in the GroupBox then that's because you added it to the GroupBox. If you drag and drop a control on another container control then it will be a child of that container. If a container control is selected and you double-click a control in the Toolbox then, again, the new control will be a child of the container. If you want a control to be a child of the form then you need to add it to the form, either by dragging and dropping it on the form or selecting the form and then double-clicking in the Toolbox. As you already have the TextBox in the GroupBox, you should use the drag and drop option to drag it out of the GroupBox. You can then position it using the Properties window, i.e. edit the Location property directly.

You can also use the Document Outline window to manage the control hierarchy of a form, but you'd still need to edit the Location manually.
 
Back
Top