Re: [VB6 ] 如何在PictureBox上用滑鼠點兩點畫線?

看板Visual_Basic作者 (月之殤)時間18年前 (2006/05/02 16:47), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/6 (看更多)
※ 引述《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
文章代碼(AID): #14Lnowdh (Visual_Basic)
討論串 (同標題文章)
文章代碼(AID): #14Lnowdh (Visual_Basic)