I want to access Form1 elements from another class file (chartscopier.cs for example), but I can't change textbox1 text from chartscopier.cs.
How can I do this?
Here is my code:
Form1.cs
namespace TEST
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var CopyCharts = new System.Threading.Timer(chartscopier.CopyGraph, null, 0, 60000);
}
}
}
chartscopier.cs
namespace TEST
{
class chartscopier
{
//var Timer = new Timer(CopyGraph, null, 0, 60000);
public static void CopyGraph(object data)
{
Stopwatch strTimer = new Stopwatch();
WebClient WC = new WebClient();
IConfigSource BaseConfig = new IniConfigSource(@"D:\NEWROBOT\CONFIG.ini");
string LogDir = BaseConfig.Configs["GENERAL"].Get("Log Dir");
string ImgDir = BaseConfig.Configs["GENERAL"].Get("IMG Dir");
string[] Clients = BaseConfig.Configs["CLIENTS"].GetKeys();
foreach (string Client in Clients)
{
strTimer.Start();
//Console.WriteLine(Client);
IConfigSource ClientConfig = new IniConfigSource(@"D:\NEWROBOT\" + Client + ".ini");
string[] Services = ClientConfig.Configs["SERVICES"].GetKeys();
foreach (string Service in Services)
{
string url = BaseConfig.Configs["CLIENTS"].Get(Client);
string param = ClientConfig.Configs["SERVICES"].Get(Service);
string html = WC.DownloadString(url + param);
// Cargar doc en HPACK
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
// LINQ para generar imagenes
var img = doc.DocumentNode.SelectSingleNode("//img[1]");
var src = img.Attributes["src"].Value;
string uIMG = url + src;
WC.DownloadFile(uIMG, @ImgDir + Client + "\\" + Service + ".png");
}
strTimer.Stop();
TimeSpan ts = strTimer.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
strTimer.Reset();
// WANT TO WRITE HERE Form1.TextBox1.text = "RunTime " + elapsedTime;
}
}
}
}