Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 21st, 2005, 03:30 AM
Authorized User
 
Join Date: Sep 2003
Location: , , United Kingdom.
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 14, p483 - custom colours

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
__________________
Visit my site: http://www.drybonesuk.com
  #2 (permalink)  
Old October 30th, 2005, 10:25 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Patrick,

Have you downloaded the code for the book and try to run this program? Have you compared your code against the sample downloaded code? Try these two things and see if it doesn't help.

Thearon


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 example pkumar@ech BOOK: Professional Jakarta Struts 0 November 15th, 2006 09:10 AM
Chapter 14 - Custom Data Sources skypilot85202 BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 June 8th, 2006 02:15 PM
Chapter 14 JonG BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 March 21st, 2006 10:04 PM
Ch. 13/14 creating own custom controls...problem.. Chimlim BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 August 10th, 2005 04:21 AM
Chapter 14 Mike Smith BOOK: Professional C#, 2nd and 3rd Editions 2 January 4th, 2004 05:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.