Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Dynamically creating panels and text boxes

Dynamically creating panels and text boxes

Scheduled Pinned Locked Moved Visual Basic
help
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    portreathbeach
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • P portreathbeach

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      P 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        P Offline
        P Offline
        portreathbeach
        wrote on last edited by
        #3

        Sorry, I did use: Dim lblTitle As New Label, Bu, my question is, how to dynamically create a panel with a Label in it.

        D A 2 Replies Last reply
        0
        • P portreathbeach

          Sorry, I did use: Dim lblTitle As New Label, Bu, my question is, how to dynamically create a panel with a Label in it.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          P 1 Reply Last reply
          0
          • D Dave Kreskowiak

            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

            P Offline
            P Offline
            portreathbeach
            wrote on last edited by
            #5

            Excellent. I used: 'panel1.controls.add(txtTitle)' and it worked fine. Thanks again

            1 Reply Last reply
            0
            • P portreathbeach

              Sorry, I did use: Dim lblTitle As New Label, Bu, my question is, how to dynamically create a panel with a Label in it.

              A Offline
              A Offline
              arcticbrew
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups