我有一個顏色選擇器,我使用的圖片與MouseMove
而不是Click
事件,以便允許顏色顯示「即時」,但是當我離開了界限的圖像,我得到一個錯誤,不能想到處理它的最佳方式。動態顏色選擇器在vb.net
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If isWithin(DirectCast(sender, PictureBox), New Point(e.X, e.Y)) And e.Button = Windows.Forms.MouseButtons.Left Then
Dim bmptmp As New Bitmap(Me.PictureBox1.Image, Me.PictureBox1.Width, Me.PictureBox1.Height)
Dim clrtmp As Color = bmptmp.GetPixel(e.X, e.Y) '<--- error here
...
...
End If
End Sub
我寫的isWithin
功能,並把它添加到檢查的If
上面一個可能的方式,但是這似乎沒有工作:
Public Function isWithin(pic As PictureBox, pnt As Point)
Dim rct1 As New Rectangle(pic.Top, pic.Left, pic.Width, pic.Height)
Dim rct2 As New Rectangle(pnt.X - 1, pnt.Y - 1, 1, 1)
Return rct1.IntersectsWith(rct2)
End Function
錯誤我收到是
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Drawing.dll - Additional information: Parameter must be positive and < Height
(或< Width
如果我走得太遠)。我認爲這是因爲e.X
或e.Y
不再大於0或小於高度或寬度(這正是我試圖用isWithin
函數檢查的結果)
可能很高興知道*哪個*錯誤。你可能會有其他人在場,因爲那裏有一些資源可能沒有妥善處理。 – Plutonix 2014-09-01 15:01:56
@Plutonix啊,是的,將在一分鐘內重新創建錯誤。正如我已經解決它,我忘了包括在帖子的末尾 – bmgh1985 2014-09-01 15:10:21
@Plutonix現在補充說,錯誤信息 – bmgh1985 2014-09-01 15:22:15