Results 1 to 1 of 1
Thread: [VB.NET] Dynamic Controls
11-21-2010, 01:59 PM #1
- Join Date
- Nov 2010
[VB.NET] Dynamic Controls
What is a dynamic control you ask?
Well a dynamic control is a control that is created whenever you need it there. (No this is not dragging and dropping a control onto the form).
For instance let's say when a user clicks a button, you want to make buttons appear according to what they put in the text box. This is somewhat on how you would do it.
Dim controlCount As Integer Dim controlButton() As Button Dim controlPositionTop As Integer = 19 Dim controlButtonName As String = "Button" Dim controlNamecounter As Integer = 1
control is going to be our accumulator for the control array we are setting up. The control array is declared with controllButton().
controlPositionTop is basically telling it how far down on the form you want this. You could also set a variable for left if you wanted to. When I was writing a program that I needed to do this in, I just needed top.
And controlButtonName is the name of the base name of the control.
ControlnameCounter is basically setting itself to one so when the array goes through and places the controls, each one with have a unique name. (EX: button ,button1 ,button2)
Lets continue on:
For core = 1 To 5 controlCount += 1 ReDim Preserve cpuCoreProgressbar(cpu) controlButtonName = controlButtonName & controlNamecounter.ToString
controlButton(controlCount ) = New Button With controlButton(controlCount ) .Name = controlButtonName .Size = New Size(100, 20) .Location = New Point(51, controlPositionTop ) End With
And finally the counters and the next:
cputop += 22 cpuLabeltop += 20 cpuLableCount += 1 controlNamecounter += 1 Next me.Refresh()