Robert,
First, you have to expose the listbox, either by making its
accessibility public, or by exposing it through a property of some kind.
Then, you would pass a reference to the form to the class that you want to
use it, by setting a property, or passing it through a method. A form is
like any other object which has properties, methods, and fields. You have
to pass it around to access it.
Hope ths helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com
"Robert" <ro*****************@softech.ro> wrote in message
news:un**************@TK2MSFTNGP10.phx.gbl...
Hi
I have an Form1 class generated with studio with an listbox on it.
how can i access this listbox from other classes ?
public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.ListBox listBox1;
private void button1_Click(object sender, System.EventArgs e)
{
listBox1.Items.Add("some text");
}
}
public class ServerClass : MyTestInterface
{
public override string MyFirstMethod(string what)
{
// here i want to add some text to Form1.listbox1
return "" + what;
}
}