Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am making a skin program that will allow a user to preview his/her progress on a form created programatically. Well what I was wondering is if any knows a way of creating the controls for that form using a string for the name??

 

Dim ProgramName as String

ProgramName = "PoopList"

Dim ProgramName as New ComboBox
ProgramName.Show

 

Anybody got any ideas??

When in doubt.... use the sledge Hammer!!
Posted

JCreationsInc

 

Here is something to get you started:

 


   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Call ComboCreator()
   End Sub

   Private Sub ComboCreator()
       Dim x As Integer
       Dim sProgramName As String = "PoopList"
       For x = 1 To 10
           Dim cmbProgramName As New ComboBox()
           cmbProgramName.Top = x * 20
           cmbProgramName.Name = sProgramName & x

           Me.Controls.Add(cmbProgramName)
       Next
   End Sub

 

Create a new form, add a button to it and then put the above code in.

 

georg

  • *Experts*
Posted

And if you use what georg showed you and you want to access them later with code use this:

Dim ctrl As Control
For Each ctrl In Me.Controls
  If TypeOf ctrl Is ComboBox
       If ctrl.Name = "Combo1" 'or whatever number and name you set to it
              'Do something to the combobox
       End If
  End If
Next

Posted

Not exactly :-)

 

You need to program a recursion, I think.

 

me.controls only contains the "top level" controls. More often than not these are GroupBoxes and panels.

.nerd
  • *Experts*
Posted
Oh, you mean tab controls. It wont contain the tabs as they belong to the tabcontrol, not the form. I thought you meant that you need recursion for every control thats not a container. You only need recursion for those that have their own child controls.
Posted

woa nelly

 

I should check my posted threads more often. I found the solution right after posting this thread here is what I used...

 

'In the load event of the form:
Dim DynamicCombo As New ComboBox()

'Set the properties and display the control
DynamicCombo.Name = "PoopList"
DynamicCombo.DropDownStyle = ComboBoxStyle.DropDownList
DynamicCombo.Items.Add("First List Item")
DynamicCombo.Items.Add("Second List Item")
DynamicCombo.Items.Add("Third List Item")
DynamicCombo.SelectedIndex = 0
Me.Controls.Add(DynamicCombo)
DynamicCombo.Show()

'This code is in the skin drawing procedure of my class:
'Loop through all the controls on the window and get our control
Dim OurCombo As Integer, ComboName As ComboBox
For OurCombo = 0 To ControlCount - 1
   If Window.Controls.Item(OurCombo).Name = "PoopList" Then
       ComboName = Window.Controls.Item(OurCombo)
   End If
Next

'Get the combobox Properties
ComboName.Left = "10"
ComboName.Top = "10"
ComboName.Width = "100"
ComboName.BackColor = color.black
ComboName.ForeColor = color.white
ComboName.Font = font.arial

 

It seems like it is working pretty good. Thank you anyways for your help you dudes are groovy baby yeah!

When in doubt.... use the sledge Hammer!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...