-
October 22nd, 2019, 11:22 PM
#1
Why does the Form_Paint event run continuously and only draw once ?
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 ?
Code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//progressBar1.Visible = false;
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) //PaintEventArgs 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;
}
}
}
-
October 23rd, 2019, 01:25 PM
#2
Re: Why does the Form_Paint event run continuously and only draw once ?
Do you know how to use a debugger?
-
October 23rd, 2019, 10:30 PM
#3
Re: Why does the Form_Paint event run continuously and only draw once ?
Of course I know how to debugger, many ways, the simple way I'm doing in the above example is to use labels
-
October 24th, 2019, 12:58 AM
#4
Re: Why does the Form_Paint event run continuously and only draw once ?
 Originally Posted by dongtrien
Of course I know how to debugger, many ways, the simple way I'm doing in the above example is to use labels
What do labels have to do with stepping through code in a debugger?
-
October 24th, 2019, 03:45 AM
#5
Re: Why does the Form_Paint event run continuously and only draw once ?
Depending on the case of troubleshooting, but using step by step debugging or running continuously to get the results, my case is needed to get the results of the Form_Paint event to run ? So do you edit my code to make it work ?
-
October 24th, 2019, 05:55 AM
#6
Re: Why does the Form_Paint event run continuously and only draw once ?
 Originally Posted by dongtrien
Depending on the case of troubleshooting, but using step by step debugging or running continuously to get the results, my case is needed to get the results of the Form_Paint event to run ? So do you edit my code to make it work ?
You need to use debugging techniques to isolate the problem. I can't do it for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
On-Demand Webinars (sponsored)
|