vb动态添加控件的事例

前端之家收集整理的这篇文章主要介绍了vb动态添加控件的事例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Private Sub Form_Load()Call DataBase sql = "Select 姓名,年龄 From 通讯" adoRs.Open sql,adoCon,1,3 adoRs.MoveFirstEnd SubPrivate Sub Form_Activate()ReDim lb(adoRs.RecordCount) ReDim tx(adoRs.RecordCount)For i = 0 To adoRs.RecordCount - 1Set lb(i) = Me.Controls.Add("vb.label","mylbhd" & i)lb(i).Top = 200 + i * 500lb(i).Left = 100lb(i).BackColor = RGB(100,150,200) lb(i).Visible = True Set tx(i) = Me.Controls.Add("vb.textBox","mytx" & i)mLeft = 100mTop = 200tx(i).Top = 200 + i * 500tx(i).Left = 1400tx(i).BackColor = RGB(100,200)tx(i).Visible = TrueNextadoRs.MoveFirsti = 0Do Until adoRs.EOFtx(i).text = adoRs.Fields("年龄") lb(i).Caption = adoRs.Fields("姓名") Next i = i + 1adoRs.MoveNextLoop adoRs.Close: Set adoRs = Nothing adoCon.Close: Set adoCon = NothingEnd Sub

猜你在找的VB相关文章