Change Position of label and text box based on user input

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
Hello all -

First I want to mention that I am not in school, nor have any assignments that require me to search for help with development. I create software at work to help our system be easier (internally).....

With that said -

I need to create a program that allows the user select which labels and text boxes they wish to see on a windows form. There will be a database involved and I will have each text box bound to the database. When the form is opened - all the text boxes (with their associated label) will be present. (just like a regular form for entering first name, last name, box number, box location etc...).

I will have another form that will have check boxes with all the names of each label/textbox name where the user can check which each textbox they want to see on the other form (these will be a My.Settings)... so...

it will kinda look like this:

VB.NET:
If checkbox1.checked = True Then
form1.textbox1.visible = True
Else
form1.textbox1.visible = False

I am not worried about the above code (if it is incorrect) as I will figure that part out..... :)

What I do have a question for is if I have 50 or so text boxes and labels on a form and the user checks a check box that is at the bottom of the form - how can I have it rearrange the form and create a nice looking form without text boxes all over the place?

Example:

just for this purpose this is what it will look like "out of the box"

before.jpg

After the user clicks the check boxes to show them visible or not - this is what I get:

after.jpg

And this is what I need:

shouldbe.jpg

I am not sure how to put them in order with no spaces between the controls (as there could be 100 or so on the form)....

Also - it would be nice to have the drag and drop effect (I can figure that one out on my own, but do not know how to keep the locations the user drags and drops to save as they close their form)

Thanks in advanced.

daveofgv
 
Thanks JohnH.

I tried it, however, it appears to be putting all labels on top and text boxes under (flow direction property)... I will play around with the properties, but how to make the form stay with label on top and textbox under the associated label?

first name:
(textbox here)

last name:
(textbox here)

etc...

instead of:

first name
last name
(textbox)
(textbox)
 
JohnH....

Am I correct by saying that I will need to put each label and textbox in their own FlowLayoutPanel (then all in one FlowLayoutPanel)- this way it will keep them together - as well as - set the settings to be visible when the checkbox is checked?

It seems to work - however - if you have any other idea's I would be much appreciated.

daveofgv
 
FlowDirection.TopDown sounds like the flow you're after. The controls lay out in the order you add them in code, in designer you can position controls any way you like.
 
Thanks JohnH

I will play around with it.... I will have over 200 text boxes and controls.... it will be a headache to add each one in order they need to be :)

Thanks for your help once again.
 
You can also design a UserControl that have a set of child controls you want to keep together.
 
Hi JohnH...

Please disregard the last reply. I understand what you ment.
That will be a good idea as I can add the flow control to the user control.

Thanks
 
I thought you meant you had one label and one textbox that should be kept together as if they were one control, that is what a UserControl is for. Of course a UserControl can have dynamic aspects by itself too.
 
I have about 200 plus text boxes with a label that is associated with each text box. Example would be a label that says "first name" and under it a text box that is binded to a database feild for first name.

If i did a user control for each pair would give me 200 plus user controls, correct?
 
No, you only design one UserControl. Then you create multiple instances of it just like when you create multiple buttons from the Button class, labels from the Label class and so on. I can't believe you haven't understood classes yet.
 
Thanks JohnH....

I do understand classes - I was only trying to put together using the FlowLayoutPanel Control. Granted, I am not the best programmer and have never been to school for programming (all self taught), however, there are a lot of controls that I have never used before - one is the FlowLayoutPanel.

I will play around with it and see if I have any issues. If so, I will probably attach a sample for you to look at - if that's OK?

I would like to apologize for my confusion... :)

Thanks
 
Back
Top