我的的自定义控件的坐标如何取得呢,奇怪呢
left 和TOP 在移动后都是0了呢, 我调测的时候 在控件的move 事件中能取到 X,Y ,但是在设断点调测模式下有X,Y的值,但如果将 msgbox x 去掉, 我就无法得到属性X和Y了 ,什么原因呢 ,我就想取得移动后控件的坐标 LEFT 和 height
http://topic.csdn.net/t/20020708/15/858627.html这里说的是我的原因吗? 好像不是
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
RaiseEvent Mousemove(Button, Shift, X, Y)
MsgBox X
img_x = X (传递给属性X)
img_y = Y(传递给属性y)
End If
End Sub
[解决办法]
在定义MouseMove事件时用Pubilc属性.
这一句RaiseEvent Mousemove(Button, Shift, X, Y)怎么在MouseMove事件的里面呢?应在用户控件的开头.
[解决办法]
这个定义没有(通用里面定义):Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
[解决办法]
Public Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
RaiseEvent Mousemove(Button, Shift, X, Y)
img_x = X --------这里的参数X的位置无法传递到主程序中, 我在主程序里调用ctr.img_x 为 0,
但我在此处加一个端点,或msgbox 后,ctr.img_x这个参数就有数值,奇怪
End If
===一下是属性定义
Private img_x, img_y As Single
Public Property Get ctr_x() As Single
ctr_x = img_x
End Property
Public Property Let ctr_x(ByVal NewValue As Single)
img_x = NewValue
PropertyChanged "ctr_x"
End Property
[解决办法]
1、在标准模块中定义2个全局变量:
Public getUsercontrolX As Long, getusercontrolY As Long
2、用户控件中这样定义事件:
...............
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
...............
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, X, Y)
getUsercontrolX = X: getusercontrolY = Y
Debug.Print X, Y
End Sub
[解决办法]
刚才测试一下,不用定义全局变量。在主程序用户控件的MouseMove事件中直接可以输出鼠标值。
只要定义事件正确。
[解决办法]
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
...............
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then ---------得判断一下是否按住左键开始移动 , 因此 放在if 里边就打印不出来呀 ,我就打印 0,16呢
RaiseEvent MouseMove(Button, Shift, X, Y)
getUsercontrolX = X: getusercontrolY = Y
Debug.Print X, Y
end if
End Sub
[解决办法]
我在控件里加了2个 text 文本框,居然显示不出来X ,Y
RaiseEvent MouseMove(Button, Shift, X, Y)
getUsercontrolX = X: getusercontrolY = Y
text1.text=x
text2.text=y
[解决办法]