主题:在VFP中可以画任意四边形吗
cqcxy
[专家分:60] 发布于 2010-04-15 08:33:00
[size=3]在VFP中可以画任意四边形吗?或者是将一个四边形旋转一定的角度?[/size]
3 楼
hw2007name [专家分:4790] 发布于 2010-04-15 11:28:00
PARAMETERS nOneX,nOneY,nTwoX,nTwoY,nThreeX,nThreeY,nFourX,nFourY
**注意这8个参数是从最左边起顺时针的四个点的坐标值。
LOCAL nPTCount,nXy[5,2],nScMaxX,nScMaxY
nPTCount=PARAMETERS()
IF nPTCount#8
MESSAGEBOX("缺少参数!",64,"信息")
RETURN .F.
ENDIF
IF VARTYPE(nOneX)#"N" OR VARTYPE(nOneY)#"N" OR VARTYPE(nTwoX)#"N" OR VARTYPE(nTwoY)#"N" OR;
VARTYPE(nThreeX)#"N" OR VARTYPE(nThreeY)#"N" OR VARTYPE(nFourX)#"N" OR VARTYPE(nFourY)#"N"
MESSAGEBOX("所有参数都应为数据值型!",64,"信息")
RETURN .F.
ENDIF
**最左上起顺时针的四个坐标点.
nXy[1,1]=nOneX
nXy[1,2]=nOneY
nXy[2,1]=nTwoX
nXy[2,2]=nTwoY
nXy[3,1]=nThreeX
nXy[3,2]=nThreeY
nXy[4,1]=nFourX
nXy[4,2]=nFourY
nXy[5,1]=nOneX
nXy[5,2]=nOneY
nScMaxX=THIS.Width
nScMaxY=THIS.Height
**处理坐标
IF MIN(nXy[1,1],nXy[1,2],nXy[2,1],nXy[2,2],nXy[3,1],nXy[3,2],nXy[4,1],nXy[4,2])<0 OR;
MAX(nXy[1,1],nXy[2,1],nXy[3,1],nXy[4,1])>nScMaxX OR ;
MAX(nXy[1,2],nXy[2,2],nXy[3,2],nXy[4,2])>nScMaxY
MESSAGEBOX("坐标超出表单范围!",64,"信息")
RETURN .F.
ENDIF
FOR I=1 TO 4
J=PADL(I,1)
thisform.RemoveObject("boxline&J.")
thisform.RemoveObject("boxLABEL&J.")
thisform.AddObject("boxline&J.","line")
thisform.AddObject("boxLABEL&J.","LABEL")
THISFORM.boxLABEL&J..VISIBLE=.T.
THISFORM.boxLABEL&J..CAPTION="第"+J+"边"
THISFORM.boxLABEL&J..autosize=.t.
thisform.boxline&J..visible=.t.
thisform.boxline&J..lineslant=IIF((nXy[I,1]<nXy[I+1,1] AND nXy[I,2]<nXy[I+1,2]) or (nXy[I,1]>nXy[I+1,1] AND nXy[I,2]>nXy[I+1,2]),"\","/")
thisform.boxline&J..left=MIN(nXy[I,1],nXy[I+1,1])
thisform.boxline&J..top=MIN(nXy[I,2],nXy[I+1,2])
thisform.boxline&J..width=ABS(nXy[I,1]-nXy[I+1,1])
thisform.boxline&J..height=ABS(nXy[I,2]-nXy[I+1,2])
THISFORM.boxLABEL&J..top=thisform.boxline&J..top+(thisform.boxline&J..height-THISFORM.boxLABEL&J..height)/2
THISFORM.boxLABEL&J..left=thisform.boxline&J..left+(thisform.boxline&J..width-THISFORM.boxLABEL&J..width)/2
ENDFOR
将此代码添加到一个表单的新方法中,比如添加一个新方法名:mybox,在表单运行时,再运行:
thisform.mybox(x1,y1,x2,y2,x3,y3,x4,y4)&&通过给定的四个坐标值的8个参数将会自动在表单上画一个四边形(只有四个边,也可能交叉成两个三角形。)