java 动态控件_如何在运行时动态创建控件

我可以与您分享我在运行时创建一些ComboBox的过程示例 .

Private Sub Agrega_Combo(Unidades As Integer)

'Procedimiento para agregar los ComboBox, etiquetas y unidades a la lista.

Dim i, j As Integer

Dim Cmb As Control

Dim Lbl As Control

'Ciclo para crear los ComboBox y Etiquetas en el 'ArrUnidades'

For i = 1 To UBound(ArrUnidades)

'Agrega el ComboBox

Set Cmb = Me.Controls.Add("Forms.combobox.1")

'Se establece el nombre y la posición del nuevo ComboBox

With Cmb

.Name = "Combobox" & i

.Left = 66

.Width = 36

If i = 1 Then

.Top = 34

Else

.Top = 34 + (24 * (i - 1))

End If

End With

'Agrega la Etiqueta'

Set Lbl = Me.Controls.Add("Forms.label.1")

With Lbl

.Name = "Label" & i

.Caption = ArrUnidades(i) & " :"

.Left = 30

.Width = 36

If i = 1 Then

.Top = 38

Else

.Top = 38 + (24 * (i - 1))

End If

End With

'Ciclo para agregar las unidades indicadas al llamar el procedimiento.

For j = 1 To Unidades

Me.Controls("ComboBox" & i).AddItem j

Next j

'Selecciona el primer valor de la lista.

Me.Controls("ComboBox" & i).Text = Me.Controls("ComboBox" & i).List(0)

Next i

End Sub

希望能帮助到你 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值