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

看板Visual_Basic作者 (月之殤)時間18年前 (2006/05/02 17:12), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串6/6 (看更多)
※ 引述《cppkiller (cppkiller)》之銘言: 引言恕刪 在下提供兩種寫法 都是由閣下的程式修改而成 也都或有利弊...謹供參考指教 第一種寫法 Dim X1,X2,Y1,Y2,Length as Single Dim Counter as Boolean Private Sub Form_Load() Picture1.DraWidth=10'把設定的東西放在這裡比較好 End Sub Private Sub Picture1_MouseDown((Button As Integer, Shift As_ Integer, X As Single, Y As Single) Picture1.Pset(X,Y),RGB(255,0,0) Counter=Not(Counter) If Counter Then X1=X;Y1=Y Else X2=X;Y2=Y End if End Sub Private Sub Command1_Click() Length=Sqr((X1-X2)^2+(Y1-Y2)^2) Picture1.Line (X1,Y1) - (X2,Y2) , vbBlue Print Length End Sub 第二種寫法 Dim X1(1),Y1(1),Length as Single Dim Counter as Byte Private Sub Form_Load() Picture1.DrawWidth=10 End Sub Private Sub Picture1_MouseDown(Button As Integer, Shift As_ Integer, X As Single, Y As Single) Picture1.Pset(X,Y),RGB (255,0,0) Counter=(Counter+1) Mod 2 X1(Counter)=X Y1(Counter)=Y End Sub Private Sub Command1_Click() Length=Sqr((X1(0)-X1(1))^2+(Y1(0)-Y1(1))^2) Picture1.Line (X1(0),Y1(0))-(X1(1),Y1(1)),vbBlue Print Length End Sub 以耗用資源來說...第一種會比較好.... 不過以程式長度和後續仍有使用到XY座標的狀況則是第二種較適用 -- 懷抱酸水半滿 若誤子弟無心 一揖還請指教 但望前行提攜 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.81.88.26
文章代碼(AID): #14LoAIYI (Visual_Basic)
討論串 (同標題文章)
文章代碼(AID): #14LoAIYI (Visual_Basic)