المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Run Time Error in simple C# windows app



C# Programming
08-25-2010, 12:20 PM
Hello everyone,

I am a freshman in C# and stuck with a stupid problem.

class ProjectDoc
{
// there is a panel in the form //
private System.Windows.Forms.Panel panelProjectDoc;
this.panelProjectDoc = new System.Windows.Forms.Panel();
this.Controls.Add(this.panelProjectDoc);

public Point myfunc(Point dropPoint)
{
int X_snap = 0;
int Y_snap = 0;
// .... do something .... //
return new Point(X_snap, Y_snap);
}

private void Filter_Click(object sender, EventArgs e)
{
BuildBlock buildBlock = new BuildBlock();
this.panelProjectDoc.Controls.Add(buildBlock);
buildBlock.******** = myfunc(new Point(900, 400)); // This works OK //
}
}

class BuildBlock : UserControl
{
private void BuildBlock_MouseUp(object sender, MouseEventArgs e)
{
Point p = new Point(0, 0);
Point q = new Point(0, 0);
p = this.********;
q = (Parent as ProjectDoc).myfunc(p); // ----- Run Time ERROR on this line ----//
this.******** = q;
}
}

Above code gives run time error when mouseUp event occurs.
[ System.NullReferenceException ]

However, if i replace the line :

this.panelProjectDoc.Controls.Add(buildBlock);
with
this.Controls.Add(buildBlock);
it does not give error (however, this way is not what i want )
any idea how to eliminate the error ?

- me