Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Code to create controls in VB.NET


Message #1 by "Robert Mottram" <rmottram@b...> on Wed, 29 May 2002 12:35:52


Hello Robert,

You can try something like this

'Create a class that inherits from System.Windows.Forms.TextBox  
Public Class My_TextBox
    Inherits System.Windows.Forms.TextBox

    Public Sub My_TextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.TextChanged
     'This is for example
      messagebox.show(me.text)
     end sub

end class

'from the form use the following code
Dim iX as integer = 100
Dim iY as integer = 0
Dim iFieldCount as integer = 6
Dim i as integer = 0

Private My_TextBox() As My_TextBox

           for i = 1 to iFieldCount

                    ReDim Preserve My_TextBox(i)
                    My_TextBox(i) = New My_TextBox()

                    iY = 35 * i
                    With My_TextBox(i)
                      .name = "TB" & i
                      .Location = New System.Drawing.Point(iX, iY)

                     end with
'Add controls to the form
    .Controls.Add(My_TextBox(i))
         next

Hope this helps

Regards
Ola

> -----Original Message-----
> From: Robert Mottram [mailto:rmottram@b...] 
> Sent: Wednesday 29 May 2002 12:36
> To: professional vb
> Subject: [pro_vb] Code to create controls in VB.NET
> 
> I have just moved to VB.NET and I am trying to create controls in my
> Code. 
> I want a number of 'identical' text boxes, lables and buttons. I don't 
> know how many until I get to a point in the code. 
> When in VB 6 I could use control arrays, but these no longer exist.
> Does anyone know how I create a control in Code partway through the 
> program, I would also like to be able to set all the buttons to use the 
> same code when they are pressed.
> 
> Thanks 
> 
> Robert
> 
> 
> 
> 



  Return to Index