Dynamically creating panels and text boxes
-
I am writing an application that needs lots of things dynamically created, Labels etc. Here is the code I use to add a label to the form: Dim lblTitle as label With lblTitle .Left = 24 .Top = 24 .Width = 632 .Height = 48 .BackColor = Color.Black .ForeColor = Color.White .Font = New Font("Arial", fontsize, FontStyle.Regular) .Enabled = True .Text = "Title of the song" .AutoSize = False End With controls.add(lblTitle) I want to make a scrolling label, so I need to create a panel on the form, then create a label in the panel with a width wider than the panel width, and move the .left of the label to make it look as if it is scrolling. I can do this when dropping the items onto a form normally, but not by dynamically creating them, please can someone help, I have been trying for days. Thanks
-
I am writing an application that needs lots of things dynamically created, Labels etc. Here is the code I use to add a label to the form: Dim lblTitle as label With lblTitle .Left = 24 .Top = 24 .Width = 632 .Height = 48 .BackColor = Color.Black .ForeColor = Color.White .Font = New Font("Arial", fontsize, FontStyle.Regular) .Enabled = True .Text = "Title of the song" .AutoSize = False End With controls.add(lblTitle) I want to make a scrolling label, so I need to create a panel on the form, then create a label in the panel with a width wider than the panel width, and move the .left of the label to make it look as if it is scrolling. I can do this when dropping the items onto a form normally, but not by dynamically creating them, please can someone help, I have been trying for days. Thanks
You didn't create an instance of the label. Change your first line to this:
Dim lblTitle As New Label
Dave Kreskowiak Microsoft MVP - Visual Basic
-
You didn't create an instance of the label. Change your first line to this:
Dim lblTitle As New Label
Dave Kreskowiak Microsoft MVP - Visual Basic
Sorry, I did use: Dim lblTitle As New Label, Bu, my question is, how to dynamically create a panel with a Label in it.
-
Sorry, I did use: Dim lblTitle As New Label, Bu, my question is, how to dynamically create a panel with a Label in it.
Create the panel using the same method, add it to the Controls collection of the form. Create the label the way you're doing it now but add it to the Controls collection of the Panel, not the form.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
Create the panel using the same method, add it to the Controls collection of the form. Create the label the way you're doing it now but add it to the Controls collection of the Panel, not the form.
Dave Kreskowiak Microsoft MVP - Visual Basic
Excellent. I used: 'panel1.controls.add(txtTitle)' and it worked fine. Thanks again
-
Sorry, I did use: Dim lblTitle As New Label, Bu, my question is, how to dynamically create a panel with a Label in it.
Set the parent property of the label to the panel you create. Set the parent property of the panel to the form on which you want it to appear. The labels location coordinates will be relative to the top left corner of the panel. If you want the panel to show on the form you must set its visibility property to true and call BringToFront. You must do the same for the label so it shows on the panel.