Write to a listbox in another form

Asked

Viewed 81 times

0

Good stack.

I am developing a small application for automatic backup of Mysql and SQL Server databases. The application is to be made in Windows Forms + C#.

I thought to implement something similar to a "console", being actually a listbox that will save the logs. My idea was to be able to store the logs inside this listbox. For example:

14:22:34 - Vou começar a backup a base de dados: user_control
14:23:10 - Terminei o backup de: user_control C:/backups

Now on to the question. How can I send class content to this listbox? I have multiple classes and multiple forms, but I always send to a single local.

I tried to create a post in the same listbox form and send arguments there. The function would take it and put it in the listbox. But I can’t call by the function without creating a new instance.

Such function. It is Form1.cs

public void addLog(string content) {
        ConsoleLog.Items.Add(content);
    }

An example of what I’ve been trying to do. It’s in frmAdd.Cs

addLog("Olá mundo");

I don’t know if I explained myself clearly, I’m willing to share more ways.

  • 1

    This depends on how your project is structured, namespaces, etc... but at first, would create a Queue<string> static, in the classes would put the text in the Queue, and in the form, would take and put in control... There is still the option to create events in the classes, and capture them in the form... a little more advanced...

  • 1

    Rovann, thanks for the idea. I took a look at Queue and quickly realized that it might be a solution. I could not find, in these mere moments, a solution to remove the text except ticks from the timer. Every second he goes there and sees if he has anything to export. Thanks again for the suggestion of Queue, I didn’t know that existed. The best :D

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.