Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27353

Generate controls at run time ?

$
0
0
Hi, I'm trying to discover how to generate controls at runtime...

I've started a small test project, Sadly I don't really know what I'm doing... I wanted an array of controls but have discovered they're not implemented in .NET...

My test program is just trying to place 15 buttons on the form, I'm assuming that once I have the method, other controls will follow in a similar manner.

Code:

Public Class Form1

    Private _button As Object

    Private Property CreateObject As Object

    Private Property Button(ByVal a As Integer) As Object
        Get
            Return _button
        End Get
        Set(ByVal value As Object)
            _button = value
        End Set
    End Property

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Populate()
    End Sub

    Private Sub Populate()  'Add a block of 15 buttons, in 3 rows of 5.
        Dim a, b, c As Integer

        For a = 1 To 15
            CreateObject = Button(a)
            Button(a).height = 50
            Button(a).width = 30
            Button(a).visible = True
            b = (a * 50) - 49
            c = 1
            While b > 250      'Button location X: 1, 51, 101, 151, 201 and 251
                c += 30            'Button location Y: 1, 31 and 61.
                b -= 250
            End While
            Button(a).location = New System.Drawing.Point(b, c)
        Next

    End Sub

End Class

This code doesn't crash, but neither does it work... I think it's just jumping past 'CreateObject'. There are no errors reported.

Poppa.

Viewing all articles
Browse latest Browse all 27353

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>