把自制控件放在VB的容器控件中,在自制控件CODE中有什么办法获取该容器控件?
解决方案 »
- 如何把在picturebox中预览的内容导出为.jpg格式?
- datediff 问题
- 怎么能让自己的窗体变成自己的设计风格,而不是默认的窗体风格.
- 代码写怎摸设置DATEGRID列的数据字段?
- 一个数组QQ(1 to 100) as int,怎样统计其重复数据分布情况,或像SQL那样分组统计,有结果马上揭帖!
- 关于data report的问题
- 如何使用加密狗来加密软件?
- =======Fraser01(王晓栋),我开始学习C++了,以后来少了,现在散分==========
- 各位大哥,菜鸟求教如何在MSFlexGrid选中一行,并且背景为兰色,Colsel,Rowsel属性如何使用
- VB中如何设置退出提示窗口
- 那位大虾知道???我要通过单击(dataGrid_Click)对dataGrid中的某一行定位,但是程序运行时中要双击才能准确定位???这是为什么??
- 天太热了,喝点可乐,呵呵
Dim i As Long
For i = 0 To UserControl.ParentControls.Count - 1
MsgBox UserControl.ParentControls.Item(i).Name
Next Form1
Picture1
自己
其它1
其它2
………如果把pictur1放在Frame1
Form1
Frame1
Picture1
自己
其它1
其它2
………
看到上面的规律了吧,呵呵呵
UserControl.ParentControls 集合从0开始 ,也是从最上层的容器开始,祝你好运!
For i = 0 To UserControl.ParentControls.Count - 1
MsgBox UserControl.ParentControls.Item(i).Name
Next 此代码在控件内部,可以自己感受一下!
For i = 0 To UserControl.ParentControls.Count - 1
MsgBox UserControl.ParentControls.Item(i).Name
Next这些就在控件内部啊,我不大明白你的意思了
是这样的,大家知道,在VB中有一个OPTION控件,如果OPTION控件在一个窗口或容器控件不只一个,在设置他的VALUE属性为TRUE时,其它OPTION控件的VALUE属性自动变为FALSE。
所以需要迭代控件所在父控件所包含的所有同类控件,并排除自己,同时设置同类控件的相关属性。
For i = 0 To UserControl.ParentControls.Count - 1
'MsgBox UserControl.ParentControls.Item(i).Name
判断是不是同类,是同类就把某一属性设为 false(包括自己)
Next
再把 me 的属性设置为true这样不就解决了吗?因为Me 就是当前被点击的一个呀!!!
通过 UserControl.ParentControls可以把所有的同类包括自己全找到并修改属性,修改完了
再在内部code中修改Me的属性!
现在已经实现了,以下是我的CODE,好象有点繁,请指教!
Public Property Let Value(ByVal new_value As Boolean)
SetOtherChecks new_value
mValue = new_value
DrawCheck
PropertyChanged ("Value")
End PropertyPrivate Sub SetOtherChecks(ByVal nowvalue As Boolean)
Dim i As Integer
Dim j As Integer
Dim k As Integer
If nowvalue = True Then
For i = 0 To UserControl.ParentControls.Count - 1
If UserControl.ParentControls.Item(i).Name = UserControl.Extender.Name Then
If UserControl.ParentControls.Item(i).Index = UserControl.Extender.Index Then
For j = i - 1 To 0 Step -1
If UserControl.ParentControls.Item(j) Is UserControl.ParentControls.Item(i).Container Then
For k = j + 1 To i - 1
If TypeName(UserControl.ParentControls.Item(k)) = UserControl.Name Then
If UserControl.ParentControls.Item(k).Value = True Then
UserControl.ParentControls.Item(k).Value = False
End If
End If
Next
For k = i + 1 To UserControl.ParentControls.Count - 1
If UserControl.ParentControls.Item(k).Container Is UserControl.ParentControls.Item(i).Container Then
If TypeName(UserControl.ParentControls.Item(k)) = UserControl.Name Then
If UserControl.ParentControls.Item(k).Value = True Then
UserControl.ParentControls.Item(k).Value = False
End If
End If
Else
'Exit For
End If
Next
Exit For
End If
Next
Exit For
End If
End If
Next
End If
End Sub
现在已经实现了,以下是我的CODE,好象有点繁,请指教!
Public Property Let Value(ByVal new_value As Boolean)
SetOtherChecks new_value
mValue = new_value
DrawCheck
PropertyChanged ( "Value ")
End Property
Private Sub SetOtherChecks(ByVal nowvalue As Boolean)
Dim i As Integer
Dim j As Integer
Dim k As Integer
If nowvalue = True Then
For i = 0 To UserControl.ParentControls.Count - 1
If UserControl.ParentControls.Item(i).Name = UserControl.Extender.Name Then
If UserControl.ParentControls.Item(i).Index = UserControl.Extender.Index Then '判断是否是控件自身
For j = i - 1 To 0 Step -1 '往回寻找父控件
If UserControl.ParentControls.Item(j) Is UserControl.ParentControls.Item(i).Container Then '判断是否为父控件
For k = j + 1 To i - 1 '设置控件自身前面的控件(在父控件中)属性
If TypeName(UserControl.ParentControls.Item(k)) = UserControl.Name Then
If UserControl.ParentControls.Item(k).Value = True Then
UserControl.ParentControls.Item(k).Value = False
End If
End If
Next
For k = i + 1 To UserControl.ParentControls.Count - 1 '设置控件自身后面的控件(在父控件中)属性
If UserControl.ParentControls.Item(k).Container Is UserControl.ParentControls.Item(i).Container Then
If TypeName(UserControl.ParentControls.Item(k)) = UserControl.Name Then
If UserControl.ParentControls.Item(k).Value = True Then
UserControl.ParentControls.Item(k).Value = False
End If
End If
Else
'Exit For
End If
Next
Exit For
End If
Next
Exit For
End If
End If
Next
End If
End Sub
SetOtherChecks new_value
mValue = new_value
DrawCheck
PropertyChanged ( "Value ")
End Property这样写不溢出和怪呢,为什么你不想想,你给每个同类修改属性就会无限的循环下去嘛
增加一个Public Property Let Value2(ByVal new_value As Boolean)
mValue = new_value
DrawCheck
PropertyChanged ( "Value ")
End Property再把下面的修改属性的赋值用 object.value2 = asdfasdfPrivate Sub SetOtherChecks(ByVal nowvalue As Boolean)
Dim i As Integer
Dim j As Integer
Dim k As Integer
If nowvalue = True Then
For i = 0 To UserControl.ParentControls.Count - 1
If UserControl.ParentControls.Item(i).Name = UserControl.Extender.Name Then
If UserControl.ParentControls.Item(i).Index = UserControl.Extender.Index Then '判断是否是控件自身
For j = i - 1 To 0 Step -1 '往回寻找父控件
If UserControl.ParentControls.Item(j) Is UserControl.ParentControls.Item(i).Container Then '判断是否为父控件
For k = j + 1 To i - 1 '设置控件自身前面的控件(在父控件中)属性
If TypeName(UserControl.ParentControls.Item(k)) = UserControl.Name Then
If UserControl.ParentControls.Item(k).Value = True Then
UserControl.ParentControls.Item(k).Value2 = False
End If
End If
Next
For k = i + 1 To UserControl.ParentControls.Count - 1 '设置控件自身后面的控件(在父控件中)属性
If UserControl.ParentControls.Item(k).Container Is UserControl.ParentControls.Item(i).Container Then
If TypeName(UserControl.ParentControls.Item(k)) = UserControl.Name Then
If UserControl.ParentControls.Item(k).Value = True Then
UserControl.ParentControls.Item(k).Value2 = False
End If
End If
Else
'Exit For
End If
Next
Exit For
End If
Next
Exit For
End If
End If
Next
End If
End Sub
SetOtherChecks new_value
mValue = new_value
DrawCheck
PropertyChanged ( "Value ")
End Property你的就相当于下面了,在一个属性赋值语句中给属性赋值,这不是循环赋值?你说会不会溢出?
Public Property Let Value(ByVal new_value As Boolean)
me.Value = new_value
End Property你的代码还真繁啊,呵呵呵,你考虑到了同一容器中的同类是吧,那样是麻烦一点,如果不考虑这种情况就容易多,但也不用这么麻烦Private Sub SetOtherChecks(ByVal nowvalue As Boolean)
Dim i As Integer, j As Integer, k As Integer
'If nowvalue = True Then 为什么false就不作任何操作,呵呵呵话外题了,如果真不操作就加上这条咯
For i = 0 To UserControl.ParentControls.Count - 1
If UserControl.ParentControls.Item(i).Name = UserControl.Extender.Name Then
If UserControl.ParentControls.Item(i).Index = UserControl.Extender.Index Then Exit For '判断是否是控件自身
End If
Next
'往回寻找父控件
For j = i - 1 To 0 Step -1
If UserControl.ParentControls.Item(j) Is UserControl.ParentControls.Item(i).Container Then '判断是否为父控件
'说明 UserControl.ParentControls.Item(j) 是自己的父在容器,这个 j 很重要
Exit For
Next
For i = 0 To UserControl.ParentControls.Count - 1
'是不是同类
If TypeName(UserControl.ParentControls.Item(i)) = UserControl.Name Then
'找到一个同类,可能包括自己,不管,判断它是不是在和自己为同一父容器
If UserControl.ParentControls.Item(j) Is UserControl.ParentControls.Item(i).Container Then
'是属性Value2喔
UserControl.ParentControls.Item(k).Value2 = Not nowvalue
End If
End If
Next
'End If
End Sub