Call Form function into another Form using C#.net

Posted by Naraayanan under C# on 4/18/2012 | Points: 10 | Views : 7102 | Status : [Member] | Replies : 5
Hi,
Project has a 3 Forms.that is Form1,Form2,Form3.One button is in the Each form.One Function is in the Form that is called Message(). I just call that function from Form3.
But It is not worked.

Form1
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
}


Function
     public  void message()
{
pictureBox1.ImageLocation = @"C:\Documents and Settings\User\My Documents\My Pictures\index.JPEG";
}


Form2
    private void button1_Click(object sender, EventArgs e)
{
this.Close();
Form3 frm = new Form3();
frm.Show();

}

Form3
Declaration
  Form1 frm = new Form1;


    private void button1_Click(object sender, EventArgs e)
{

frm.message();
this.Close();
}



But it is not worked.Please help me.why?I upload a picture in the Picture Box. how to solve this issue?Please do needful...

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/



Responses

Posted by: Gsm_Gsv on: 4/18/2012 [Member] Starter | Points: 25

Up
0
Down
Try giving different names for declaration ("frm")

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 4/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Thanks . But it is not worked

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/18/2012 [Member] Silver | Points: 25

Up
0
Down
it throws any error...?

Regards,
Singaravel M

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sunny4989 on: 4/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

"frm" is ambiguous Because for all the three forms(FORM1, FORM2, FORM3) you are creating the same object name(frm) at that point of time if u call frm.message function(frm.message()) it will be ambiguous


------------------------------------------------
Learn throughout life

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 4/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Yes , This is my error "Object reference not set to an instance of an object."

I tried the following code when form3 button event.But form1 will display one more time.
 Form1 frm1 = new Form1();

frm1.Show();
frm1.message();


I just show the form1.so form1 displays.

 Form1 frm1 = new Form1();

frm1.message();

I just try the above code.It will get "Object reference not set to an instance of an object." .So How to do this?Please give me a solution .





Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response