Dear all,
I have 2 separate code files in a C# project, one of it is a window form and the other is a c# class file..
I want to pass certain parameters entered by the user in the form to the class for it to proceed operation. How do I do that
Thanks alot.

Pass user-specified parameters from windows form to class. HOW?
amiri
I tried to mimic yr code but I cant get it workin..
I have a MainForm with a button btnSettings to get a parameter, Nb from the form called SelectForm and btnStartThread to start the longProcess. Now I have the Nb value in MainForm, how do I pass into a class (which is found in another file not in MainForm) Nb
**************************************************************
In the MainForm
public void btnSettings_Click(object sender, System.EventArgs e)
{ SelectForm oSelectForm = new SelectForm();
oSelectForm.MyParentForm = this;
if (oSelectForm.ShowDialog() == DialogResult.OK)
{ if (oSelectForm.comboChannel.SelectedIndex == -1)
Nb = -1;
else Nb = Convert.ToInt32(oSelectForm.comboChannel.SelectedItem);
}
private void btnStartThread_Click(object sender, System.EventArgs e)
{ LongProcess longProcess;
longProcess.Run();}
**************************************************************
In another separate class file LongProcess
public unsafe class LongProcess
{static long Tmp = 10; // if user did not choose a value for Tmp, default 10 will be used
....
public void Run(){a while loop running here and will be using Nb value}
}
**************************************************************
I hope I have described my problem to you clearly..
Many Thanks.
Regards,
sieweng
Keyvan Nayyeri
Class Form1 : Form
{
void button1_Click(...)
{
MyClass o = new MyClass();
o.String1 = "Hello";
o.String2 = "World";
o.SomeMethod();
/* or */
MyClass p = new MyClass("Hello", "World");
p.SomeMethod();
}
}
Class MyClass
{
public MyClass() { }
public MyClass(string s1, string s2)
{
_string1 = s1;
_string2 = s2;
}
private string _string1;
public string String1
{
get { return _string1; }
set { _string1 = value; }
}
private string _string2;
public string String2
{
get { return _string2; }
set { _string2 = value; }
}
public void SomeMethod()
{
Console.WriteLine("{0} {1}", _string1, _string2);
}
}
jeffrafter
private void btnStartThread_Click(object sender, System.EventArgs e)
{ LongProcess longProcess;
longProcess.Run(Nb);} <---- pass Nb to the Run function
public void Run(int Nb){a while loop running here and will be using Nb value}
}
Does that work
Greg
Leland