作者tpjobp (月之殇)
看板Visual_Basic
标题Re: [VB6 ] 如何在PictureBox上用滑鼠点两点画线?
时间Tue May 2 16:56:13 2006
※ 引述《cppkiller (cppkiller)》之铭言:
: ※ 引述《cppkiller (cppkiller)》之铭言:
: 现在Sub or Function not defined的问题已经解决了!
: 但是现在按CommandButton它只会对原点作直线,要如何才能做两点间的直线?
: 谢谢!
: : 那再请问我接下来的做法对不对?
: : 我要在一张图上用滑鼠点两点,然後按CommandButton就显示两点间的直线及长度!
: : 一开始我先在form1建立一个PictureBox并放入图片,然後双击图片进入code。再打入
: : Dim x1, y1, x2, y2, length As Single
要多宣告一个全域变数counter
: : Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As
: : Single, Y As Single)
: : Picture1.DrawWidth = 10
: : Picture1.PSet (X, Y), RGB(255, 0, 0)
: : Dim counter As Integer
这一个拿掉....
: : counter = 0
: : counter = counter + 1
这两行改成
counter=counter mod 2
counter=counter+1
: : Select Case counter Mod 2
: : Case 1
: : x1 = X
: : y1 = Y
: : Case 0
: : x2 = X
: : y2 = Y
: : End Select
: : End Sub
: : 然後再建立一个CommandButton,在其code打入
: : Private Sub Command1_Click()
: : length = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
: : Picture1.Line (x1, y1)-(x2, y2), vbBlue
: : Print length
: : End Sub
: : 请问各位大大我是哪里写错了!谢谢!
如果可以的话 把你的全域变数counter设为Boolean型态
这样的话
那两行只要以 counter=not(counter) 就可以取代
再把底下的 select case 以 if counter then else end if 代替似乎会比较好
--
怀抱酸水半满
若误子弟无心
一揖还请指教
但望前行提携
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.81.88.26