Hello!
Quick question.. I have been working through this book - I think it is really brialliant! - but I am getting an error that I can't solve on the above mentioned page. Your code says:
Code:
Else
'display the color dialog
If dlgColor.ShowDialog = DialogResult.OK Then
'add the new color
AddColor(dlgColor.Color)
'resize the palette to show the dialog
OnResize(New EventArgs)
End If
End If
I have put this in, and when I run the problem, I can left click, right click, and draw no problems. When I click on the background to add a custom colour though, I get the following error...
Quote:
quote:An unhandled exception of type 'System.NullReferenceException' occurred in PatrickPaint.exe
Additional information: Object reference not set to an instance of an object.
|
my full code is as follows: (hope this is ok to post it...)
Code:
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
'find the button we clicked on
Dim button As ColorPaletteButton = GetButtonAt(e.X, e.Y)
If Not button Is Nothing Then
'select this color
If e.Button = MouseButtons.Left Then
'make sure this button is not the current right
If Not button Is rightButton Then
'set the color
LeftColor = button.Color
'clear the existing selection
If Not leftButton Is Nothing Then leftButton.ButtonAssignment = _
ColorPaletteButton.ButtonAssignments.None
Invalidate(leftButton.Rectangle)
End If
'mark the button
button.ButtonAssignment = ColorPaletteButton.ButtonAssignments.LeftButton
Invalidate(button.Rectangle)
leftButton = button
'fire the event
RaiseEvent LeftClick(Me, New EventArgs)
End If
'did we click with the right?
If e.Button = MouseButtons.Right Then
'make sure the button is not the current left
If Not button Is leftButton Then
'set right colour
RightColor = button.Color
'clear the existing selection
If Not rightButton Is Nothing Then
rightButton.ButtonAssignment = _
ColorPaletteButton.ButtonAssignments.None
Invalidate(rightButton.Rectangle)
End If
'mark the button
button.ButtonAssignment = ColorPaletteButton.ButtonAssignments.RightButton
Invalidate(button.Rectangle)
rightButton = button
'fire the event
RaiseEvent RightClick(Me, New EventArgs)
End If
End If
Else
'display the color dialog
If dlgColor.ShowDialog = DialogResult.OK Then
'add the new color
AddColor(dlgColor.Color)
'resize the palette to show the dialog
OnResize(New EventArgs)
End If
End If
End Sub
could someone let me know what I am doing wrong here?
Thanks
Patrick
Visit my site:
http://www.drybonesuk.com