Reputation: 83
I am modifying an application and I need to add and remove field depending on the configuration the user set.
Right now, I use two panel that contain the corresponding field and I'm hiding and showing them when I need to. I re-size the form and relocate elements in the form accordingly. But then, it become hard to modify either of the panel and the form when you are in editing mode.
I also think that since it re-use a lot of the element, it would be unwise to create another separate form but maybe it's just me.
I'm not sure how to rearrange all of this and would really like some tips.
Upvotes: 0
Views: 105
Reputation: 4948
It seems like you are trying to adjust the form size depending on different controls. I suggest you learn about TableLayoutPanels. For each TableLayoutPanel Row/Column, you can set that Row/Column to AutoSize.
This means if there's nothing to display (aka it is hidden), your TableLayoutPanel will AutoSize accordingly.
Form1.vb [Design]
Using the following code, the TableLayoutPanel will adjust it's controls appropriately:
Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
Select Case True
Case RadioButton1.Checked 'Show Row #2
Label1.Show()
Label2.Hide()
Case RadioButton2.Checked 'Show Row #3
Label1.Hide()
Label2.Show()
End Select
End Sub
Here's the result:
Almost everything was done by the designer.
TextAlign=Center
Upvotes: 1
Reputation: 61
Create two separate sets of controls in different forms. Then import them both as composite controls. You can then hide and show as needed using the .visible control property.
Upvotes: 0