主题:请问各位:拖动表单里的容器如何实现?
吉祥鸟
[专家分:0] 发布于 2008-07-25 10:36:00
请问各位:拖动表单里的容器如何实现?
回复列表 (共13个回复)
沙发
cbl518 [专家分:57140] 发布于 2008-07-26 07:01:00
在表单的 .Load 事件中写入:
PUBLIC nX,nY
STORE 0 TO nX,nY
板凳
cbl518 [专家分:57140] 发布于 2008-07-26 07:09:00
在表单的 .DragDrop 事件中写入:
oSource.Left = nXCoord - nX
oSource.Top = nYCoord - nY
3 楼
cbl518 [专家分:57140] 发布于 2008-07-26 07:09:00
表单里的要移动的容器 .MouseMove 事件中写入:
IF nButton = 1 && Left button
nX = nXCoord - THIS.Left
nY = nYCoord - THIS.Top
THIS.Drag
ENDIF
4 楼
北京种子乐 [专家分:3710] 发布于 2008-07-26 07:33:00
今天别的活不干了,
下点功夫研究研究这三帖。
5 楼
wuzhouhong [专家分:10890] 发布于 2008-07-26 11:10:00
在要拖动的控件的父容器的DragDrop()中加入
oSource.Move(nXCoord,nYCoord) && 这句将拖动的对象移动到鼠标位置
需要拖动的控件的MouseDown()中加入
this.Drag(1)
6 楼
北京种子乐 [专家分:3710] 发布于 2008-07-26 11:38:00
真能吗?
那我可得试试。
7 楼
zxl931 [专家分:3420] 发布于 2008-07-26 14:49:00
***************************************
* 可以拖动的容器实例。 *
* 制作:zxl 2008.7.26 *
***************************************
PUBLIC ofrm
ofrm=NEWOBJECT("form1")
ofrm.Show
RETURN
DEFINE CLASS form1 AS form
DoCreate = .T.
Autocenter = .T.
Caption = "Form1"
Name = "Form1"
ADD OBJECT container1 AS container WITH ;
Top = 60, ;
Left = 84, ;
Width = 205, ;
Height = 97, ;
BackColor = RGB(0,255,255), ;
Name = "Container1"
PROCEDURE container1.MouseUp
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.MousePointer= 0
ENDPROC
PROCEDURE container1.MouseMove
LPARAMETERS nButton, nShift, nXCoord, nYCoord
WITH THIS
IF nButton=1
.LEFT=nXCoord-nX
.TOP=nYCoord-nY
ENDIF
ENDWITH
ENDPROC
PROCEDURE container1.MouseDown
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nButton=1
nX=nXCoord-this.Left
nY=nYCoord-this.top
this.MousePointer= 15
ENDIF
ENDPROC
PROCEDURE container1.Init
PUBLIC nX,nY
ENDPROC
ENDDEFINE
*结束*
8 楼
zxl931 [专家分:3420] 发布于 2008-07-26 14:59:00
**************************************************
* 利用以上拖动功能制作的分隔条,用到anchor属性, *
* 因此以下代码只能在VFP9.0运行! *
* 制作:zxl 2008.7.26 *
**************************************************
PUBLIC ofrm
ofrm=NEWOBJECT("form1")
ofrm.Show
RETURN
DEFINE CLASS form1 AS form
Top = 0
Left = 0
Height = 390
Width = 552
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
Autocenter = .T.
ADD OBJECT label1 AS label WITH ;
AutoSize = .T., ;
FontBold = .F., ;
FontName = "华文中宋", ;
FontSize = 16, ;
BackStyle = 0, ;
Caption = "分割条演示:", ;
Height = 30, ;
Left = 12, ;
Top = 12, ;
Width = 114, ;
Name = "Label1"
ADD OBJECT edit1 AS editbox WITH ;
FontSize = 10, ;
Anchor = 7, ;
Height = 168, ;
Left = 12, ;
Top = 45, ;
Width = 264, ;
ForeColor = RGB(255,0,0), ;
Value = "", ;
Themes = .T., ;
Name = "Edit1"
ADD OBJECT edit2 AS editbox WITH ;
FontSize = 10, ;
Anchor = 15, ;
Height = 168, ;
Left = 280, ;
Top = 45, ;
Width = 260, ;
ForeColor = RGB(0,128,0), ;
Themes = .T., ;
Name = "Edit2"
ADD OBJECT shape1 AS shape WITH ;
Top = 45, ;
Left = 276, ;
Height = 168, ;
Width = 4, ;
Anchor = 5, ;
BackStyle = 0, ;
BorderStyle = 0, ;
BorderWidth = 0, ;
MousePointer = 9, ;
Name = "Shape1"
ADD OBJECT shape2 AS shape WITH ;
Top = 213, ;
Left = 12, ;
Height = 4, ;
Width = 529, ;
Anchor = 14, ;
BackStyle = 0, ;
BorderStyle = 0, ;
BorderWidth = 0, ;
MousePointer = 7, ;
Name = "Shape2"
ADD OBJECT edit3 AS editbox WITH ;
FontSize = 10, ;
Anchor = 14, ;
Height = 152, ;
Left = 12, ;
Top = 217, ;
Width = 529, ;
ForeColor = RGB(0,0,255), ;
Themes = .T., ;
Name = "Edit3"
PROCEDURE shape1.MouseMove
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nButton=1
WITH THIS
IF nXCoord>100 AND nXCoord<thisform.Width-100
.ANCHOR=0
.left=nXCoord
.ANCHOR=5
ELSE
RETURN
ENDIF
ENDWITH
WITH THIS.PARENT.edit1
.ANCHOR=0
.width=MAX(nXCoord-.LEFT,0)
.ANCHOR=7
ENDWITH
WITH THIS.PARENT.edit2
.ANCHOR=0
.width=Max(.left+.width-This.left-This.width,0)
.Left=THIS.LEFT+THIS.WIDTH
.ANCHOR=15
ENDWITH
ENDIF
ENDPROC
PROCEDURE shape2.MouseMove
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nButton=1
WITH THIS
IF nYCoord>100 AND nYCoord<thisform.height-100
.Anchor=0
.top=nYCoord
.Anchor=14
ELSE
RETURN
ENDIF
ENDWITH
WITH THIS.PARENT.edit1
.ANCHOR=0
.height=nYCoord-.top
.ANCHOR=7
ENDWITH
WITH THIS.PARENT.edit2
.ANCHOR=0
.height=nYCoord-.top
.ANCHOR=15
ENDWITH
WITH THIS.PARENT.edit3
.ANCHOR=0
.height=.Height+.Top-This.Top-This.Height
.top=this.Top+this.Height
.ANCHOR=14
ENDWITH
WITH this.Parent.shape1
.anchor=0
.Height=nYCoord-.top
.anchor=5
ENDWITH
ENDIF
ENDPROC
**结束**
9 楼
北京种子乐 [专家分:3710] 发布于 2008-08-03 02:52:00
这几天好忙呀!
才倒出手来研究这个问题,先顶上来。
搞不懂的地方还要向各位高师请教喓。
10 楼
lzguang [专家分:1210] 发布于 2008-08-04 02:05:00
随意拖动,任意大小,非常精确(以容器控件为例)另:希望有人简化
一:在容器控件的 MouseDown 事件中:
OldLeft = This.Left
OldTop = This.Top
OldHeight = This.Height
OldWidth = This.Width
lnAvgCharWidth = 0.000
lnAvgCharHeight = 0.000
lnAvgCharWidth = Fontmetric(6)
lnAvgCharHeight = Fontmetric(1)
OldPosX = Mcol() * lnAvgCharWidth - This.Left
OldPosY = Mrow() * lnAvgCharHeight - This.Top
Do Case
Case nXCoord >= This.Left And nXCoord <= This.Left + 5 And nYCoord >= This.Top And nYCoord <= This.Top + 5
Do While Mdown()
If (OldHeight + ( OldTop - Mrow() * lnAvgCharHeight ))<=0
Return
Endif
If (OldWidth + ( OldLeft - Mcol() * lnAvgCharWidth )) <= 0
Return
Endif
This.Left = Mcol() * lnAvgCharWidth
This.Top = Mrow() * lnAvgCharHeight
This.Height = OldHeight + ( OldTop - This.Top )
This.Width = OldWidth + ( OldLeft - This.Left )
Enddo
Case nXCoord >= This.Left And nXCoord <= This.Left + 5 And nYCoord >= This.Top + This.Height - 5 And nYCoord <= This.Top + This.Height
Do While Mdown()
If This.Top >= Mrow() * lnAvgCharHeight
Return
Endif
If (OldWidth + ( OldLeft - Mcol() * lnAvgCharWidth )) <= 0
Return
Endif
This.Left = Mcol() * lnAvgCharWidth
This.Height = Mrow() * lnAvgCharHeight - This.Top
This.Width = OldWidth + ( OldLeft - This.Left )
Enddo
Case nXCoord >= This.Left + This.Width - 5 And nXCoord <= This.Left + This.Width And nYCoord >= This.Top And nYCoord =< This.Top + 5
Do While Mdown()
我来回复