Somebody help me? Please?
I am trying to write to textbox component located on WindowsForm from another class.
What I did wrong? Simple form is started by default form load.
After that separate 'Nonameclass' class with internal timer is created.
Timer is running. Till now it works.
I am trying to show current value in textbox located on that windowsform and I see nothing.
Can somebody help me with working solution please?
I am trying to write to textbox component located on WindowsForm from another class.
What I did wrong? Simple form is started by default form load.
After that separate 'Nonameclass' class with internal timer is created.
Timer is running. Till now it works.
I am trying to show current value in textbox located on that windowsform and I see nothing.
Can somebody help me with working solution please?
code:
namespace Test_CSharp
{
public partial class Form1 : Form
{
public static Form1 form1;
public Form1()
{
InitializeComponent();
form1 = this;
}
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)
{
}
}
}
}