按钮的拖动问题!急急!!!
我想实现当鼠标移动到按钮上时我移动鼠标向下的时候按钮的高度会随着鼠标的移动变高,同样对于向右移动的时候,按钮的宽度页会随着变宽,(前提是该按钮的
top,和left都不变变得只是宽度和高度)!!!!
望各位大侠赐教!!!
问题点数:80、回复次数:10Top
1 楼ayuu(ayuu)回复于 2002-04-16 16:09:16 得分 70
command_MouseDown(button as integer,shift as integer,x as single,y as single)
px=x
py=y
end sub
command_MouseMove(button as integer,shift as integer,x as single,y as single)
command.height=command.height+x-px
command.width=command.width+y-py
command.left=inileft
command.top=initop
end sub
其中,inileft,initop分别是按钮最初位置的left和top值,是不变的。Top
2 楼lxb529()回复于 2002-04-16 16:27:28 得分 0
试了,可是MouseDown发生在mousemove后,所以对于,px,py在mousedown中的
付值好像没用,Top
3 楼ayuu(ayuu)回复于 2002-04-16 16:29:22 得分 0
哎呀,px和py你要定义为全局变量的。
这样肯定可以的。我常用这个方法的。Top
4 楼ayuu(ayuu)回复于 2002-04-16 16:30:41 得分 0
哦,补充一下。
command_MouseMove(button as integer,shift as integer,x as single,y as single)
if button=1 then
command.height=command.height+x-px
command.width=command.width+y-py
command.left=inileft
command.top=initop
endif
end sub
这样就可以了。前面忘记写这句判断了。:)
Top
5 楼lxb529()回复于 2002-04-16 16:32:04 得分 0
按钮只要一拖动就变得很大,不是扩充到鼠标移动的位置! ayuu(ayuu)大侠
请指教!谢谢!Top
6 楼ayuu(ayuu)回复于 2002-04-16 18:04:44 得分 0
Dim px As Single, py As Single, iniheight As Single, iniwidth As Single
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
px = X
py = Y
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Command1.Height = iniheight + Y - py
Command1.Width = iniwidth + X - px
End If
End Sub
Private Sub Form_Load()
iniheight = Command1.Height
iniwidth = Command1.Width
End Sub
我试过了,肯定没有问题啦。Top
7 楼ayuu(ayuu)回复于 2002-04-16 18:05:54 得分 0
当然,你应该还要注意反向的拖动时,控件的高度和宽度不能小于0。这个判断就自己加吧。Top
8 楼505(五五)回复于 2002-04-16 19:14:51 得分 0
按钮只要一拖动就变得很大,不是扩充到鼠标移动的位置!
==================================================
可能是你的 Form1.ScaleMode=3(pixel)的缘故Top
9 楼xxlroad(土八路)回复于 2002-04-16 19:27:01 得分 0
'同意: ayuu(ayuu)
Dim px As Single, py As Single
Dim iniheight As Single, iniwidth As Single
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
px = X
py = Y
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And (iniheight + Y - py) > 0 And (iniwidth + X - px) > 0 Then
Command1.Height = iniheight + Y - py
Command1.Width = iniwidth + X - px
End If
End Sub
Private Sub Form_Load()
iniheight = Command1.Height
iniwidth = Command1.Width
End SubTop
10 楼xxlroad(土八路)回复于 2002-04-16 19:37:00 得分 10
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
Const SWP_NOMOVE = &H2
Const SWP_DRAWFRAME = &H20
Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000
Private Sub Command1_Click() '允许改变控件尺寸
ResizeControl Text1, Me
End Sub
Sub ResizeControl(ControlName As Control, FormName As Form)
Dim NewStyle As Long
NewStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
NewStyle = NewStyle Or WS_THICKFRAME
NewStyle = SetWindowLong(Text1.hwnd, GWL_STYLE, NewStyle)
SetWindowPos ControlName.hwnd, FormName.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
End SubTop




