Results 1 to 7 of 7

Thread: Dynamically create controls

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275

    Dynamically create controls

    hey,

    i've made a app. it has a addon part where the user can add buttons here and there and they can open external app's.

    how do i set it up so i can create controls on the fly?

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Dim blah as New System.Windows.Forms.Button

    blah.Left = anumber
    blah.Top = anumber
    blah.Text = 'Click Me"
    blah.Visible = True
    Form1.Controls.Add(blah)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Dynamically create controls

    This creates new instance of button object and add it to your form at runtime . Just provide some specific info related to location and size as you need .

    VB Code:
    1. Dim Butn As New System.Windows.Forms.Button()
    2.         Butn.Size = New System.Drawing.Size(150, 30)
    3.         Butn.Name = "Button1"
    4.         Butn.Text = "BUTTON1"
    5.         Me.Controls.Add(Butn)

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Mix and match both mine and Pirates code. I showed positioning of the control, he covered size.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275
    thanx

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    what about events?

    If you make controls dynamically at run time, say it could be between three to thirty textboxes, how do you code to process the unique events?

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    In this case you can use Delegates and WithEvents .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width