Batikit

Hi

I would like to know how do .net developers manage a large window application with a large number of controls, such as textbox , button, groupbox

I have seen a number of people do it this way : declare the controls as an array and initialize them one by one at run time . In this way it is easy to manage those controls because they can be accessed by array index; but this solution seems to require very good understanding of control's attribute such as its location, font etc. This could be a difficult task if the project is passed on to a less experienced developer and add changes to it.

How do you deal with it

Thanks,




Re: Visual Basic General How do you manage your controls if there are many many controls placed on the forms?

cverdon

Hi,

It depends on what you are trying to do...

If a part of the UI must be dynamic (ie generated by the code) a combination of Panel control and code can be used.

If the form is always the same, the VS designer is enough even if there are lots of control.

If some part of the form changes, then you can use user controls.

I can't be more precise without knowing what you are trying to acheive :)

Regards,
Charles





Re: Visual Basic General How do you manage your controls if there are many many controls placed on the forms?

Batikit

If it is a application with lots of controls, let's say , you have 15 labels placed on a form. Logically you would name them label1, label2, label3 ....

I found it hard to manage the labels and had to put them into array and declare them at run-time but in this way no controls will be shown on VS designer, the other developer who may continue to work on the project may find it hard to a understand what the UI looks like by looking at the code.

This is just my thoughts






Re: Visual Basic General How do you manage your controls if there are many many controls placed on the forms?

cverdon

You can have the best of both by creating the labels with the designer and adding them to an array for the processing...

Charles





Re: Visual Basic General How do you manage your controls if there are many many controls placed on the forms?

anubisascends

You can also create a user control, I have created ones that have over 100 textboxes, about 75 labels, 50 check boxes and runs calculations based on information entered into the text boxes and the check boxes that are checked.

Once you create the control, you can bring it into the application and the controls in the user control will be...bound I guess I would say, to the user control. This has really helped me manage these huge items.

The best part, if I have to change something on the user control, I am looking at that code, and pretty much, just that code, not trying to sort through code that is partially irrelevant to the control.





Re: Visual Basic General How do you manage your controls if there are many many controls placed on the forms?

spotty

Whats so difficult about managing the labels. Its really not that difficult and as the controls are put into a collection of controls on the form - you can always refer to them in For Each Loop construct and use the name by building a simple string of its prefix and additional number.

So at runtime, an example like this will write a number to each appropriate textbox.

For i as integer = 1 to 10
Dim s as string = "Textbox1" & i.tostring
Ctype(Me.Controls(s),Textbox).Text = i.tostring
Next





Re: Visual Basic General How do you manage your controls if there are many many controls placed on the forms?

Batikit

Oh, Spotty your solution is pretty nice

here is my solution, which will have the same outcome:

Private Function getGroupboxControl(ByVal grpbox_name As String) As GroupBox
Dim my_groupbox As GroupBox

Dim my_count As Integer
my_count = Me.Controls.Count

For i As Integer = 0 To my_count - 1

If TypeOf Me.Controls(i) Is GroupBox Then

my_groupbox = Me.Controls(i)
If my_groupbox.Name.Equals(grpbox_name) Then
getGroupboxControl = my_groupbox
End If
End If
Next
End Function

That's why I wonder how do the experienced developers out there deal with the similar issues.

Thanks for that code ;-)






Re: Visual Basic General How do you manage your controls if there are many many controls placed on the forms?

SJWhiteley

Experienced developers don't run into this problem because they don't create forms with huge numbers of controls. :)

You would wrapper functionality in user controls (thus it becomes a single control), giving you a heirarchial structure.