i want to call a method in FORM class from another class.
i tried all d ways i could but nothng workd.anyone please help me out........
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jean PaulPosted Dec 6, 2010, 10:47 AM
Karthik AgarwalPosted Dec 7, 2010, 1:59 AM
Ya i accpeted your answer......Thanks once again.........
Mahesh ChandPosted Dec 6, 2010, 10:03 AM
You need to make sure you write proper English grammar and don't use coded English grammar. Also, make sure title of a question is proper and it should be about the problem.
Thanks!
Karthik AgarwalPosted Dec 6, 2010, 9:54 AM
Thanks vry much the code which u hav posted is working..........thanks a lot.......if i hav any queries i'll ask u.....no pblm right..........
Jean PaulPosted Nov 30, 2010, 11:04 AM
Create a public static variable inside the form, and set the value in the constructor.
Example code is given below:
public partial class Form1 : Form
{
public static Form1 CurrentInstance;
public Form1()
{
InitializeComponent();
// Set the instance for global access
CurrentInstance = this;
}
}
After that create your two methods in the form and it should be public.
Let's assume the methods are m1() and m2() respectively.
From your class, you can invoke like this:
Form1.CurrentInstance.m1();
Form1.CurrentInstance.m2();
Please let me know if it works.. else attach your sample source so i can try fixing it.
Karthik AgarwalPosted Nov 30, 2010, 10:43 AM
I dont want to instantiate Form from another class, i just want to call two methods which are present in FORM class.In the first method call i want to enable one textbox,button present on the FORM,and in the second method call i just want to copy some text into some other textbox which is also present on the same FORM.
i tried the code u posted but the control is reaching both the methods in the FORM class and executing each and everry instruction in both the methods but i am not able to see the result in the sense neither the textbox,button are enabled nor the text got copied in to another textbox.
Jean PaulPosted Nov 30, 2010, 9:09 AM
Eg:
YourForm
{
public void MyMethod()
{
}
}
YourClass
{
public void AnotherMethod()
{
new YourForm().MyMethod();
}
}