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
Yigal BZ
1.6k
112
7.3k
C# VS2017 WPF : fail to create draw movement on form
Feb 24 2020 2:52 PM
Hi
I am tryintg to draw a moving rectangle and circle on a form using the paint method.
A button should start the process. 2nd pres should end the program.
The once variable is a global boolean set to True on start.
X1 is a global int, set to 10 on start.
Up is a global boolean, set to true on start.
Each iteeration the X1 variable is increased until 100, going down to 10, endlessly.
Two problems:
1- No movement of the drawing on the form
2- No control on the form once the program starts.
private
void
Form1_Paint(
object
sender, PaintEventArgs e)
{
Pen red =
new
Pen(Color.Red,3);
Rectangle rect =
new
Rectangle(x1, x1, x1, x1);
Rectangle circle =
new
Rectangle(x1+10, x1 + 10, x1 + 50, x1 + 50);
//Graphics g = e.Graphics;
Graphics g = CreateGraphics();
g.DrawRectangle(red,rect);
g.DrawEllipse(red, circle);
red.Dispose();
g.Dispose();
}
private
void
button2_Click(
object
sender, EventArgs e)
{
if
(once)
once =
false
;
else
Environment.Exit(0);
while
(
true
)
{
if
(up )
{
x1 += 10;
if
(x1 > 100)
up =
false
;
}
else
{
x1 -= 10;
if
(x1 <= 10)
up =
true
;
}
this
.Invalidate();
Thread.Sleep(500);
}
}
Reply
Answers (
4
)
Cannot convert between a unicode and a non-unicode SSIS
How can perform click event on one image