Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188428
  • 博文数量: 106
  • 博客积分: 3810
  • 博客等级: 中校
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 13:35
文章分类

全部博文(106)

文章存档

2014年(17)

2011年(5)

2010年(75)

2009年(9)

我的朋友

分类:

2009-12-15 13:50:37

在VB中编写自定义控件时,想要对控件产生的对象实例进行操作的时候,会有一些难度,我采用了一种折中的办法,也许效率不高,不过至少可以使用。就是利用自定义控件的HDC属性。
 
给对象添加一个HDC属性,把控件本身的HDC值传递出去。
 
这个属性是只读的。

Public Property Get hDC() As Long
    hDC = UserControl.hDC
End Property

然后建立一个函数来返回对象实例: 

然而尝试以后,还是不行,HDC似乎在运行过程中是会变化的,我增加一个变量,HdcV来保存,然后在函数中调用。

'返回控件自身的实例
Public Function AppMe() As Object
    On Error Resume Next
    Dim I As Long
    For I = 0 To UserControl.ParentControls.Count - 1
        If TypeOf UserControl.ParentControls(I) Is UCSplit Then
            If UserControl.ParentControls(I).hDCV = pHdcV Then
                Set AppMe = UserControl.ParentControls.Item(I)
                Exit For
            End If
        End If
    Next I
End Function


阅读(354) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~