listening to events causes null reference

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Torbjorn Stavas (luser_at_skip.informatik.gu.se)
Date: 09/06/04


Date: 6 Sep 2004 09:56:06 -0700

I have a form with a few panels added to it. Each of these panels are
instances
of different classes, that has inherited System.Windows.Form.Panel,
such as

class Panel1 : System.Windows.Forms.Panel
class Panel2 : System.Windows.Forms.Panel
class Panel3 : System.Windows.Forms.Panel

Each of these panels are initiated in the main form, and added to the
form with Controls.add();

So, to the problem. In panel1, i want to listen to an event in panel2.
I'm solving this by having a reference (called frmRef) to the main
form in panel1.
In panel1, i try to listen to an event in panel2 with the help of the
following code:

(Code in Panel1)
this.frmRef.panel2.AnEvent += new AnEvent(pnl2_AnEvent);

this.line gives me a null reference when starting upp the program. I
tried to initiate panel2 in panel1, and adding it to panel1's control.
Then the listening to the event in panel2 works just fine. But this
isn't what i want to do.

What am i missing here?

//Torbjorn



Relevant Pages

  • Re: Changing parent container
    ... panels) control to another panel at run time. ... container. ... I make Panel2 smaller than Panel1 to make sure I can see it in Panel1. ...
    (microsoft.public.dotnet.framework)
  • controls inside panel removed after hiding it
    ... I have a form with 2 panels. ... Inside panel1 there's a button which, when clicked, hides panel1 and ... Inside panel2 there's another button which, when clicked, hides panel2 ... mypanel1button_click(object sender, System.EventArgs e) ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: splitter bar in SplitContainer
    ... I don't know how to display the splitter bar, which is between Panel1 and Panel2. ... I think one way might be to draw only the bottom/top border of the Panels, but I don't know how to do that. ... It may be worth looking at the document outline to see what controls sit where. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Newbie Questions - Easy
    ... You have just one physical page with 4 Panels to represent each logical ... When they click the "next" button, hide Panel1 and show Panel2. ... I do not wish to store each step to DB and I do not wish to ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: draw line on a form/panel and remove/clear the line?
    ... why do you want to draw a line and then erase it?. ... My form contains 2 panels. ... a line using drawline in the paint event of panel2 at the edge of panel2 ... The line redraws as I scroll down which is desired ...
    (microsoft.public.dotnet.languages.vb)