文章探索:   分类:    关键字:  
  + 栏目导航
  + 相关文章
文本框中光标位置的获得
用VB导入导出你的IE收藏夹
VB应用程序访问SQL Server方法探讨
VB访问SQL Server数据库技术全揭密
自动上网抓数据的机器人
自己的IE——用VB制作浏览器
VB中如何保存Webbrowser中的整个页面..
在VB中该如何控制其它程序的弹出窗口..
保存webbrowser中的HTML内容
破译动网验证码的简单方法
轻松获取QQ密码
VB.NET获取硬盘序列号的方法
WEBBROWSER 技巧一(收藏)
VB自动登陆网络站点详解(二):Inet..
获取webbrowser控件网页的源码
WebBrowser控件说明
关于用VB做更漂亮的窗体的思考
VB中访问存储过程的几种办法
VB6中改变屏幕的分辨率和刷新频率
VB编写一个能显示百分比的自定义进度..
公农历转换VB类
VB.NET窗口渐淡关闭
使用VB实现邮箱自动注册(二):修改..
VB.NET轻松实现任务栏程序
VB.NET启动外部程序
利用vb实现图片上传
VB实现局域网内的文件传输
VB 一个Function传回多个值
在VB中实现多线程
VB 手机号码编码程序


技术教程 -> VB教程 ->  
自制控件方面的有关知识
来源:转载   人气:948   录入时间:2007-11-8
     在程序中注册和注销 OCX 控件 98-7-20
   声明(在本例子里使用的是 ComCtl32.OCX,如果是其他,使用相应的名称):
   Declare Function RegComCtl32 Lib "ComCtl32.OCX" _
   Alias "DllRegisterServer" () As Long
   Declare Function UnRegComCtl32 Lib "ComCtl32.OCX" _
   Alias "DllUnregisterServer" () As Long
   Const ERROR_SUCCESS = &H0
   
   使用:
   
   If RegComCtl32 = ERROR_SUCCESS Then
   MsgBox "Registration Successful"
   Else
   MsgBox "Registration Unsuccessful"
   End If
   
   If UnRegComCtl32 = ERROR_SUCCESS Then
   MsgBox "UnRegistration Successful"
   Else
   MsgBox "UnRegistration Unsuccessful"
   End If
   
   2.
   建立可下拉选择的属性
   例如在 BorderStyle 中有以下的四个选择:
   0 - None
   1 - Dashed
   2 - Single Line
   3 - Double Line
   4 - 3D
   首先在控件中定义以下的集合:
   Enum BorderType
   None
   Dashed
   [Single Line]
   [Double Line]
   [3D]
   End Enum
   然后就可以把属性的类型设置好:
   Public Property Get BorderStyle() As BorderType
   Border = m_BorderStyle
   End Property
   
   Public Property Let BorderStyle(ByVal New_BorderStyle As BorderType)
   m_BorderStyle = New_BorderStyle
   PropertyChanged "BorderStyle"
   End Property
   
   3.
   缺省值和可选参数
   VB5 加强了函数参数方面,可用以下的代码实现参数缺省:
   
   Property Get Value(Optional index As Long = 1)
   ...
   End Property
   也可使用另一个方法(慢):
   
   Property Get Value(Optional index As Long)
   If IsMissing(index) Then index = 1
   ...
   End Property
   
   4.
   多个参数的属性
   在自制的控件中,可能需要对某个属性传递多个值:
   
   Property Let Test (arg1 As String, arg2 As String, arg3 As Integer)
   End Property
   
   '用以下的方法传递参数:
   Test(arg1,arg2) = arg3
   
   5.
   使用数组做属性
   定义一个 variant 类型的属性,即可用它来做数组。
   下面定义了一个 CArray 类。
   
   Private m_MyArray As Variant
   
   Public Property Get MyArray() As Variant
   MyArray = m_MyArray
   End Property
   
   Public Property Let MyArray(a As Variant)
   m_MyArray = a
   End Property
   
   可用以下的方法使用:
   
   Private m_Array As CArray
   Private mArr(3) As String
   
   Private Sub Form_Load()
   Set m_Array = New CArray
   mArr(1) = "One"
   mArr(2) = "Two"
   mArr(3) = "Three"
   m_Array.MyArray = mArr()
   '或者
   'm_Array.MyArray = Array("One", "Two", "Three")
   End Sub
   
   Private Sub Form_Unload(Cancel As Integer)
   Dim i As Integer
   For i = 1 To UBound(m_Array.MyArray)
   MsgBox m_Array.MyArray(i)
   Next
   End Sub
   




Copyright(C)2007-2024 广州市佳沛数码科技有限公司 版权所有
公司地址: 广州市荔湾区东漖北路560号511室
电话:020-81803473 传真:020-81544987