TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dong Lam Trien
827
986
147.1k
Why does the Form_Paint event run continuously and only draw
Oct 22 2019 8:49 PM
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.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
;
}
}
}
Reply
Answers (
6
)
Public user, how to access the customer site in withoutlogin
Unhandled exception. System.IO.FileNotFoundException: Could