我有一個PictureBox控件。當我點擊控件上的圖像時,事件處理程序被觸發。如何處理ArgumentOutOfRangeException?
這裏是事件處理程序:
Private Sub pbImageHolder_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles pbImageHolder.Click
Dim clickPoint As Point = MousePosition
Dim img As Bitmap = New Bitmap(pbImageHolder.Image)
pixelColor = img.GetPixel(clickPoint.X, clickPoint.Y)
For i As Integer = 0 To img.Width
For j As Integer = 0 To img.Height
Next
Next
End Sub
的問題是,我此行中得到:
pixelColor = img.GetPixel(clickPoint.X, clickPoint.Y)
這是例外:
System.ArgumentOutOfRangeException了未處理
消息=參數必須爲正,並且寬度爲<。參數名稱:X
PARAMNAME = X
源= System.Drawing中
任何想法,我怎麼能修復代碼?
PictureBox.SizeMode混淆了這段代碼。正如它與OP一樣。 – 2012-08-01 21:13:58
@HansPassant好點。 OP也使用MousePosition - 這不可能是好事。 – LarsTech 2012-08-01 21:19:18