private void Form1_Load(object sender, EventArgs e)
{
System.Random rnd = new Random();
Task task = new Task(()=>
{
while(true)
{
this.Text = rnd.Next(0, 1000).ToString();
}
});
task.Start();
}
using System;
using System.Windows.Forms;
namespace WinFormsApp
{
public partial class MainForm : Form
{
private readonly Random _random;
private readonly Timer _timer;
public MainForm()
{
InitializeComponent();
_random = new Random();
_timer = new Timer();
_timer.Interval = 500;
_timer.Tick += OnTimerTick;
}
private void OnFormLoad(object sender, EventArgs e)
{
_timer.Start();
}
private void OnTimerTick(object sender, EventArgs e)
{
label.Text = _random.Next(0, 1000).ToString();
}
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 2);
e.Graphics.DrawLine(pen, 0, 0, 150, 150);
pen.Dispose();
}