[C#] Use a listBox from a Class.
#10


Let me understand you want to create a new form(window) and add items to the list.

 

Here is a simple example how you can controll another class, from another class.

//the form class
public partial class Form1 : Form
{
private MyClass mc = new MyClass();
public Form1()
{
InitializeComponent();
mc.setup(new object[] { this });
}
private void button1_Click(object sender, EventArgs e)
{
mc.Add();
}

//interface method from the window form
public void addTextLine(string msg)
{
listBox1.Items.Add(msg);
}
}

//my class
class MyClass
{
//an instance to the form class
public Form1 windowsForm;

//get the data from yje form class
public void setup(object[] args)
{
if (args != null)
{
windowsForm = (Form1)args[0];
}
}

//methods to access the form class
public void Add()
{
windowsForm.addTextLine("stuff");
}
}

 

no, i made a Class "MySql1" for my Commands etc..

But now i wanna fill the listBox from Form1 .. and it wont work ..

i try now wizas recommend



Messages In This Thread
[No subject] - by Nikolee - 08-20-2012, 12:07 PM
[No subject] - by HateMe - 08-20-2012, 01:10 PM
[No subject] - by Nikolee - 08-20-2012, 01:45 PM
[No subject] - by Wizatek - 08-20-2012, 01:51 PM
[No subject] - by Nikolee - 08-20-2012, 02:19 PM
[No subject] - by HateMe - 08-20-2012, 03:07 PM
[No subject] - by Nikolee - 08-20-2012, 03:15 PM
[No subject] - by Wizatek - 08-20-2012, 04:02 PM
[No subject] - by someone - 08-20-2012, 04:34 PM
[No subject] - by Nikolee - 08-20-2012, 04:52 PM
[No subject] - by someone - 08-20-2012, 05:05 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)