Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing Combo Box, Labels, and TextBoxes on the Fly 2

Status
Not open for further replies.

dataman86

Technical User
Oct 11, 2008
104
US
Hello,

Is it possible to have Visual Basic Coding to create Combo Boxes, TextBoxes, and Labels on the Fly? I need to have these created only on page one of my form and not have it appear on the other pages. I have created One Template Form to use where I am going from page top page with lines and totals. I want a Combo Box for Month, day, and year to just appear on the First Page Only.

I have created this by researching, but it is not working:

I have code:

Public Class Form2
Private buttonPanel As New Panel
Private WithEvents btnClose As New Button
Private WithEvents btnNext As New Button
Private WithEvents btnPrev As New Button
Private WithEvents btnSave As New Button
Private WithEvents btnCalc As New Button
Private WithEvents TxtBatch As New ComboBox



Private Sub AddButtons(ByVal bPrev As Boolean, ByVal bNext As Boolean)
'places buttons on form
With btnClose
.Text = "Close"
.Location = New Point(25, 0)
.TabStop = True
.TabIndex = 90
.Width = 75
.Height = 23
.Visible = Not (bPrev) ' Visible on last page only, first page could be last page
End With

With btnNext
.Text = "Next >"
.Location = New Point(25, 50)
.TabStop = True
.TabIndex = 91
.Width = 75
.Height = 23
.Visible = bNext ' visible only if more than one page and not the last page
End With

With btnPrev
.Text = "< Prev"
.Location = New Point(25, 25)
.TabStop = True
.TabIndex = 92
.Width = 75
.Height = 23
.Visible = bPrev
End With

With TxtBatch
.Location = New Point(932, 219)
.Size = New Point(66, 20)
.Visible = bNext
End With


I can get it to work with Buttons, but it want work for the Combo Boxes.

 
Yes you can create controls on the fly, which is what is happening in the designer code of your project (for example, Form1.Designer.vb). What you'll see there that you don't have in your code sample above is the process of adding the control(s) to the form. You've created the controls but they're just sitting out in memory with no way of becoming visible.

With that said, I think you're making this overly complicated. You could do this in design time by adding a Panel, then adding your controls inside the Panel. Then by changing the Panel1.Visible property depending on whether or not you're on the first "page" will hide or show all the child controls.
 
It is the exact same process as with the text boxes. The only difference is that since you are doing withevents you don't have to do the addhandler. The only thing I see right away that is wrong is you don't add the buttons to anything. The form or the panel which ever is the one you wanted to add it to.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top