Witam,
nie mogę sobie poradzić z powyższym zadaniem. Potrzebuję wyświetlić stan licznika, który "leci" w osobnej klasie.
Startuję klasę Nonameclass w której działa sobie timer. Chciałbym wyświetlić jego wartość w textboxie, który znajduje się na formatce Form1.
Dziekuję za pomoc.
```namespace Test_CSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Run_Nonameclass();
}
private void Run_Nonameclass()
{
Nonameclass newNonameclass = new Nonameclass();
}
}
}
namespace Test_CSharp
{
class Nonameclass
{
private System.Timers.Timer mycounter;
public int cnt;
Form1 frm = new Form1();
public Nonameclass()
{
cnt = 0;
mycounter = new System.Timers.Timer();
mycounter.Interval = 1000;
mycounter.Start();
mycounter.Elapsed += mycounter_Tick;
}
private void mycounter_Tick(object source, System.Timers.ElapsedEventArgs e)
{
try
{
cnt = cnt + 1;
frm.textBox1.Text = cnt.ToString();
}
catch (Exception ex)
{
}
}
}
}