在VB中如何动态的去生成一个Label控件

在VB中如何动态的去生成一个Label控件,第1张

Dim l1 As Label

Set l1 = Me.Controls.Add("VB.Label", "l1")

l1.Caption = "我是动态创建的Label控件"

l1.Left = 300

l1.Top = 150

l1.Visible = True

适用于VB6

下面是我为你写的一个函数,我用的名字是label1 设其index=0(让它为一个数组控件)

Private Function CreateLable(nstr As String) As Integer

Dim i As Integer

Load Label1(Label1.Count)'这个是添加,如果重新排列 ,一个for 下面的改下!

With Label1(Label1.Count - 1)'如果要重新再排时,这里稍作修改就行!

.AutoSize = True

.Caption = nstr

.Move IIf(Me.ScaleWidth >.Width + Label1(Label1.Count - 2).Left + Label1(Label1.Count - 2).Width, Label1(Label1.Count - 2).Left + Label1(Label1.Count - 2).Width, 0), _

IIf(Me.ScaleWidth >Label1(Label1.Count - 2).Left + Label1(Label1.Count - 2).Width + .Width, Label1(Label1.Count - 2).Top, Label1(Label1.Count - 2).Top + Label1(Label1.Count - 2).Height)

.Visible = True

End With

CreateLable = Label1.Count - 1

End Function


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11464060.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存