On Panel.hide - An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll .NETCF

An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll
Everytime I try to hide one particular panel in my application I am getting the error above
I have several other panels which I am showing and hiding throughout the application without any problems - I have tried creating a new panel and copying the controls from the old one into the new one ... I'm losing my mind here!  This was working and I don't know why it isn't now ...
AlisonBallardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
It's kind of difficult to troubleshoot these kinds of errors over the wire without code or more information to explain what you are trying to do.

What .NET version are you working with?

Bob
0
AlisonBallardAuthor Commented:
Sorry ... I think its nothing to do with hiding the panel ... I am using a signature control which I downloaded ... it wa working fine ... However when I hide my panels and want to display the Signature Capture section I get the error.  I'm developing for Windows Mob 2003 Pocket PC (using VB.NET CF)

The code for the control is as follows :
***********************************************
'      SignatureControl class
'      --
'      Collects and displays a signature. The signature is made up of
'      a list of line segments. Each segment contains an array of points
'      (x and y coordinates).
'
'      Draws to a memory bitmap to prevent flickering.
'
'      Raises the SignatureUpdate event when a new segment is added to
'      the signature.


' Custom control that collects and displays a signature.
Public Class SignatureControl
      Inherits Control

      ' gdi objects
      Private _bmp As Bitmap
      Private _graphics As Graphics
      Private _pen As New Pen(Color.Black)

      ' list of line segments
      Private _lines As New ArrayList

      ' the current line segment
      Private _points As New ArrayList
      Private _lastPoint As New Point(0, 0)

      ' if drawing signature or not
      Private _collectPoints As Boolean = False

      ' notify parent that line segment was updated
      Public Event SignatureUpdate As EventHandler

      ' List of signature line segments.
      Public ReadOnly Property Lines() As ArrayList
            Get
                  Return _lines
            End Get
      End Property

      ' Return the signature flattened to a stream of bytes.
      Public ReadOnly Property SignatureBits() As Byte()
            Get
                  Return SignatureData.GetBytes(Me.Width, Me.Height, _lines)
            End Get
      End Property

      Public Sub New()
      End Sub

      Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            ' blit the memory bitmap to the screen
            ' we draw on the memory bitmap on mousemove so there
            ' is nothing else to draw at this time (the memory
            ' bitmap already contains all of the lines)
            CreateGdiObjects()
            e.Graphics.DrawImage(_bmp, 0, 0)
      End Sub

      Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
            ' don't pass to base since we paint everything, avoid flashing
      End Sub

      Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
            MyBase.OnMouseDown(e)

            ' process if currently drawing signature
            If Not _collectPoints Then
                  ' start collecting points
                  _collectPoints = True

                  ' use current mouse click as the first point
                  _lastPoint.X = e.X
                  _lastPoint.Y = e.Y

                  ' this is the first point in the list
                  _points.Clear()
                  _points.Add(_lastPoint)
            End If
      End Sub


      Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
            MyBase.OnMouseUp(e)

            ' process if drawing signature
            If _collectPoints Then
                  ' stop collecting points
                  _collectPoints = False

                  ' add current line to list of segments
                  Dim points(_points.Count - 1) As Point
                  Dim i As Integer
                  For i = 0 To _points.Count - 1
                        Dim pt As Point = CType(_points(i), Point)
                        points(i).X = pt.X
                        points(i).Y = pt.Y
                  Next i

                  _lines.Add(points)

                  ' start over with a new line
                  _points.Clear()

                  ' notify container a new segment was added
                  RaiseSignatureUpdateEvent()
            End If
      End Sub

      Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
            MyBase.OnMouseMove(e)

            ' process if drawing signature
            If _collectPoints Then
                  ' add point to current line segment
                  _points.Add(New Point(e.X, e.Y))

                  ' draw the new segment on the memory bitmap
                  _graphics.DrawLine(_pen, _lastPoint.X, _lastPoint.Y, e.X, e.Y)

                  ' update the current position
                  _lastPoint.X = e.X
                  _lastPoint.Y = e.Y

                  ' display the updated bitmap
                  Invalidate()
            End If
      End Sub

      ' Clear the signature.
      Public Sub Clear()
            _lines.Clear()
            InitMemoryBitmap()
            Invalidate()
      End Sub

      ' Create any GDI objects required to draw signature.
      Private Sub CreateGdiObjects()
            ' only create if don't have one or the size changed
            If _bmp Is Nothing Then
                  InitMemoryBitmap()
            ElseIf _bmp.Width <> Me.Width Or _bmp.Height <> Me.Height Then
                  InitMemoryBitmap()
            End If
      End Sub

      ' Create a memory bitmap that is used to draw the signature.
      Private Sub InitMemoryBitmap()
            ' load the background image
            _bmp = Global.LoadImage("sign here.png")

            ' get graphics object now to make drawing during mousemove faster
            _graphics = Graphics.FromImage(_bmp)
      End Sub

      ' Notify container that a line segment has been added.
      Private Sub RaiseSignatureUpdateEvent()
            RaiseEvent SignatureUpdate(Me, EventArgs.Empty)
      End Sub
End Class
***********************************************


I Add the control to my form as follows

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.IO
Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Runtime.InteropServices
Imports FieldSoftware.PrinterCE_NetCF

Public Class MainFrm

    Inherits System.Windows.Forms.Form
...
    ' custom signature control
    Private WithEvents _signature As SignatureControl = New SignatureControl
...

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        'add signature control to form


        _signature.Location = areaSignature.Location
        _signature.Size = areaSignature.Size
         Me.Controls.Add(_signature)

End Sub
(areaSignature is a panel with    
0
Bob LearnedCommented:
How are you "hiding" the panel, and showing the Capture section?

Bob
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

AlisonBallardAuthor Commented:
I'm calling :
Transpanel.hide
The capture section is visible and is behind the 'TransPanel' located directly on the form
0
Bob LearnedCommented:
I still can't see anything leaping off the page, yet.

Capture section = SignatureControl?
TransPanel = ?

Bob
0
AlisonBallardAuthor Commented:
Sorry ... I'm in a bit of a flap today
The signature control is positioned on the form
The TransPanel is a Panel contained a variety of control including some text boxes and a listview
When I hide the transpanel so that the only signature control (area) is visible I get the error
   An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll
   The line
   Public Class MainFrm
   is highlighted (just MainFrm)

When I comment out
  Me.Controls.Add(_signature)
I don't get the error ...

Alison
0
AlisonBallardAuthor Commented:
.. Don't get the error but don't get the control with either (obviously) ...
Alison
0
Bob LearnedCommented:
That exception happens when you have an unhandled exception in something like a Paint event handler, and the debugger gets confused, and can't display the correct information.  This is a very difficult problem to narrow down.  I can't give you a ready answer to this one, unfortunately.  :(

Bob
0
g_johnsonCommented:
The only time I ever had this error it was because I had a dim statement and tried to reference the variable while it was still "nothing"

Therefore I suspect this section of code:
 Dim points(_points.Count - 1) As Point
               Dim i As Integer
               For i = 0 To _points.Count - 1
                    Dim pt As Point = CType(_points(i), Point) <----- maybe this line??
                    points(i).X = pt.X
                    points(i).Y = pt.Y
               Next i

This is just a wild guess based on my one experience with this error
0
Bob LearnedCommented:
Anything is possible.  Can you put in breakpoints, and test?

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlisonBallardAuthor Commented:
Will give it a whirl in the morning
0
AlisonBallardAuthor Commented:
I think I have got the error ...  Very stupid.  I had changed the Root Namespace .. so my LoadImage function was unable to find the graphic ... I'm going to split the points ...

      Private Sub CreateGdiObjects()
            ' only create if don't have one or the size changed
            If _bmp Is Nothing Then
                  InitMemoryBitmap()
            ElseIf _bmp.Width <> Me.Width Or _bmp.Height <> Me.Height Then
                  InitMemoryBitmap()
            End If
      End Sub

      ' Create a memory bitmap that is used to draw the signature.
      Private Sub InitMemoryBitmap()
            ' load the background image
            _bmp = Global.LoadImage("sign here.png")

            ' get graphics object now to make drawing during mousemove faster
            _graphics = Graphics.FromImage(_bmp)
      End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.