動(dòng)態(tài)加載控件,有諸多好處,
以前以為,只有在VC中才能動(dòng)態(tài)加載控件,而在VB中,只能定義一個(gè)數(shù)組,然后采用Load方式加載。近日編碼,才發(fā)現(xiàn),原來VB中也可以方便的動(dòng)態(tài)加載。
舉例子總結(jié)一下,免得以后到處查:
1:動(dòng)態(tài)加載VB固有的控件。
如:加載一個(gè)文本框
Controls.Add "VB.TextBox", "txtDynamic", Me
With Me!txtDynamic
.Visible = True
.Width = 2000
.Text = "0"
End With
2:如何綁定事件呢?
Private WithEvents txtTest As TextBox
Set txtTest = Me!txtDynamic
Private Sub txtTest_KeyPress(KeyAscii As Integer)
End Sub
3:動(dòng)態(tài)加載自定義控件。注意,一定需要License。
Licenses.Add "Project2.UserControl1", "kaghfadhghlaahnhigaaohaaogjgmaehoanb"
Set ctlExtender = Controls.Add("Project2.UserControl1", "MyControl")
With ctlExtender
.Visible = True
.Top = 1000
.Left = 1000
End With
4:那么,自定義控件如何生成License?
1:工程屬性頁>>General Require license key 勾上。
2: 打開生成的VBL文件,第二行中有Key。一看便知。
5:如何綁定自定義控件的事件呢?
Private WithEvents ctlExtender As VBControlExtender
Private Sub ctlExtender_ObjectEvent(Info As EventInfo)
Debug.Print Info.Name
End Sub
嗯,參數(shù)怎么?。?
如:自定義控件的事件為:
Public Event EditChange(ByVal Param1 As String)
取參數(shù)就是:
Info.EventParameters("Param1")
6:對(duì)了,有License的自定義控件不動(dòng)態(tài)加載,直接使用,需要License嗎,如何注冊(cè)?
需要。 把VBL文件當(dāng)作reg文件注冊(cè)一下就好了。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。