Modify form attributes of the main app from extern class

Hi to all,
I've this little problem that I can't resolve from my own, in a windows application created using VS2005.
As you know I've a principal class, called program.cs, where the main create and launch the principal form application, which class is called form, as this code:

static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form());
}

Now, I've another class called Thread, that I create and run from the Form class.

In this Thread class, I want to execute a method that add object to one listbox in my Form.
I've created a public method in Form class but I can't call it from the Thread class because I don't know the name of the instance of the application.

How can I do

Thank you






Answer this question

Modify form attributes of the main app from extern class

  • sri111

    Are you using object of thread class in the object of Form Class Can you post your class's code

    Best Regards,



  • felipe17

    RizwanSharp wrote:


    Caioshin wrote:
    Hi to all,

    Now, I've another class called Thread, that I create and run from the Form class.

    In this Thread class, I want to execute a method that add object to one listbox in my Form.
    I've created a public method in Form class but I can't call it from the Thread class because I don't know the name of the instance of the application.

    To add an object to a ListBox why do you need instance of application

    listBox.Items.Add(someObject);

    What's the problem actually Clarify it!

    Best Regards,



    Yes I know how is the method, but I can't simply use the listbox, because it belong to the Form class.
    I'm in the thread class, and if I want to modify properties of another class (that is not a static class, is the class of the Form, instanced and executed by the main method in the code that I've written in my first post) I need to know the name of the instance that I want to modify, isn't it

    So I don't know how to access to the listbox, its name is not accessible from another class (even if the class is public, and even if I use Form.listbox), and I can't declare a static method in the Form class to modify the listbox because I'm in a non-static class.

  • Araki66

    Ok, I've my Form class, called Form1.cs, that can access to all properties of the windows form.
    I've another class, called ThreadClass.cs, where I start a thread (in its constructor) in this way:
    public ThreadClass()
    {
    ThreadListen = new Thread(new ThreadStart(StartListening));
    ThreadListen.Start();
    }

    In the Form1 class, I instance the ThreadClass so the new Thread is created and can be executed. I do this in this way:

    public partial class Form1 : Form
    {
    ThreadClass ObjectThreadClass = new  ThreadClass();
    .....


    Now, in the Form1 class, that is the graphic class, I've a listbox and I can modify or add object to it.
    I want only create a method in this class, that permit to other class to add object to the listbox.
    I've create a public method called AddToList that only add object to the listbox, but from the thread class I can't access to it, because I don't know the name of the instance of the Form class.

    In a few words: I can't access to the Listbox from the ThreadClass (or I don't know how I can), but I need to do it.


  • Simon FERQUEL

    nobody can tell me how to modify properties of windows form from another class

    I need something similar to this but I don't know how to obtain the same results with a Listbox

  • mf915

    Caioshin wrote:
    Hi to all,

    Now, I've another class called Thread, that I create and run from the Form class.

    In this Thread class, I want to execute a method that add object to one listbox in my Form.
    I've created a public method in Form class but I can't call it from the Thread class because I don't know the name of the instance of the application.

    To add an object to a ListBox why do you need instance of application

    listBox.Items.Add(someObject);

    What's the problem actually Clarify it!

    Best Regards,



  • Modify form attributes of the main app from extern class