I have the following code, I put a label in Form_Paint to track the number jump, I see the label jumping continuously but e.Graphics.DrawString(...) only looks once, does anyone know why ?
- public partial class Form1: Form {
- public Form1() {
- InitializeComponent();
-
- progressBar1.Minimum = 0;
- progressBar1.Maximum = 100;
- this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
- }
- int iNum = 0;
- private void btnDrawText_Click(object sender, EventArgs e)
- {
- progressBar1.Value = 0;
- progressBar1.Visible = true;
- this.timer1.Interval = 100;
- this.timer1.Enabled = true;
-
- }
- private void ShadowedTextPaint(PaintEventArgs e, int num) {
- using(Font font1 = new Font("Times New Roman", 250, FontStyle.Bold, GraphicsUnit.Pixel)) {
- PointF pointF1 = new PointF(310, 270);
- e.Graphics.DrawString(num.ToString(), font1, Brushes.LightGreen, pointF1);
- lblNum.Text = num.ToString();
- }
- }
- private void Form1_Paint(object sender, PaintEventArgs e) {
- ShadowedTextPaint(e, iNum);
- }
- private void timer1_Tick(object sender, EventArgs e) {
- if (progressBar1.Value < 100) {
- Random rd = new Random();
- iNum = rd.Next(0, 999);
- progressBar1.Value++;
- } else {
- this.timer1.Enabled = false;
- progressBar1.Visible = false;
- }
- }
- }