首先,新建一個(gè)ActiveX Control工程,在界面上放一個(gè)TextBox,然后,打開(kāi)代碼窗口,輸入如下代碼:
Public a As String
Public Property Get Value() As String a = Text1.Text Value = a End Property
Public Property Let Value(ByVal vNewValue As String) a = vNewValue Text1.Text = a End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Call PropBag.ReadProperty("Value") End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag) PropBag.WriteProperty "Value", a End Sub
現(xiàn)在,我們已經(jīng)為控件封裝好了一個(gè)“Value”屬性,接下來(lái),我們?cè)O(shè)置該屬性為控件的默認(rèn)屬性,步驟如下: 在代碼窗口打開(kāi)的前提下,點(diǎn)擊“工具”菜單,選擇“過(guò)程屬性”,在“名稱”一欄中選擇“Value”
然后,點(diǎn)擊“高級(jí)”按鈕,在“過(guò)程標(biāo)識(shí)符”中,選擇“(缺?。保詈?,點(diǎn)擊“應(yīng)用”按鈕,編譯即可。
其實(shí),這樣也可以,用記事本打開(kāi)相應(yīng)的ctl文件,這里我們?cè)O(shè)置“Value”屬性為控件的默認(rèn)屬性,找到: Public Property Get Value() As String a = Text1.Text Value = a End Property
添加一句:Attribute Value.VB_UserMemId = 0,讓它變成: Public Property Get Value() As String Attribute Value.VB_UserMemId = 0 a = Text1.Text Value = a End Property 然后,保存,編譯即可 |
|