|
| hello
i'm new in c# and i have problem in variable scopes, well i previously do some things in java and there were no bigger problems but in C# i have probelms on my every step.
First of all
in my main file of project i have following code to catch the button event
private void buttoncorner_Click(object sender, System.EventArgs e)
{
MapView areaView = new MapView(viewPict.Width,viewPict.Height);
viewPict.Image = areaView.scrbmp;
MyColor areaBkg = new MyColor(255,0,0);
areaView.setBkg(areaBkg);
}
and file with definition of MapView Class
public class MapView
{
public Bitmap scrbmp;
public Graphics graph;
public MapView(int viewWidth,int viewHeight)
{
scrbmp = new Bitmap(view.Width,view.Height);
Graphics graph = Graphics.FromImage(this.scrbmp);
Pen penCurrent = new Pen(Color.Blue);
graph.DrawLine(penCurrent, 10,10,50,50);
}
public void setBkg(MyColor givenBkg)
{
this.graph.Clear(Color.FromArgb(givenBkg.r,givenBkg.g,givenBkg.b));
}
firstly i create 'MapView' areaView, and this works quite fine but when i trying to use setBkg method i have An unhandled exception of type 'System.NullReferenceException' occurred in SmartDeviceApplication5.exe
while debug, when cursor is pointed over 'graph' in setBkg method, tooltip shows that it is undefinied value ??!! but i don't know when i do a misteake, i give a value to this variable in cosntructor, so where is the problem ?
while code designing even intelisense shows that 'graph' is a valid field visible inside setBkg method
i hope that somone be able to help me |
|