您的位置:首页 > 移动开发 > Objective-C

动态生成控件并定位

2012-03-10 10:54 316 查看
 

Public Class form1

    Private a(0 To 8) As Control

    Private b(0 To 8) As Object

    Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click

        For i As Int16 = 0 To 8

            If i < 3 Then

                b(i) = New Int16

                b(i) = 5

                Debug.WriteLine(CType(b(i), Integer) & " 是" & TypeName(b(i)), ToString)

            ElseIf i < 6 Then

                b(i) = New String(CType("Welcome", Char()))

                b(i) = "Welcome"

                Debug.WriteLine(CType("Welcome", Char()) & " 是" & TypeName(b(i)), ToString)

            ElseIf i < 7 Then

                b(i) = New Label With {.BorderStyle = BorderStyle.Fixed3D, .Size = New Size(60, 60), .Location = New Point(60, 220)}

                Controls.Add(CType(b(i), Control))

                If TypeOf b(i) Is Label Then

                    Debug.WriteLine(TypeName(b(i)) & "是标签", ToString)

                End If

            End If

        Next

    End Sub

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

        ReDim a(0 To 8)

        For i As Int16 = 0 To 8

            If i < 3 Then

                a(i) = New Label With {.BorderStyle = BorderStyle.Fixed3D, .Size = New Size(60, 60), .Location = New Point(i * 60, 0)}

                Controls.Add(a(i))

            ElseIf i < 6 Then

                a(i) = New Button With {.Size = New Size(60, 60), .Location = New Point((i - 3) * 60, 70)}

                Controls.Add(a(i))

            ElseIf i < 9 Then

                a(i) = New TextBox With {.Size = New Size(60, 60), .Location = New Point((i - 6) * 60, 150)}

                Controls.Add(a(i))

            End If

        Next

    End Sub

End Class

本程序在 Visual Basic.net 2010下设计通过
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息