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
Hieu Ha
NA
24
1.9k
winform c# onPaint() block UI
Oct 30 2017 2:25 AM
I have two UserControls which added in a form in my winforms project, one with the function to draw a string and make it scrolling from right to left and the other draw another string and make it scroll from bottom to top over and over again controlled by calling Invalidate() inside a while(true) loop.But when one of my string becomes too long, about 1000 characters the UI Thread is blocked, so my questions are: What am I doing wrong? is there a better way to make text scrolling??? and bellow is my snippet of code:
int
scrollTextSpeed = 100;
bool
scrollingText =
true
;
Thread updateUI ;
void
init()
{
updateUI =
new
Thread(updateScrollText);
updateUI.Start(); }
void
updateScrollText() {
while
(
true
)
{
if
(scrollingText)
{
Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal,
new
MethodInvoker(Invalidate)); Thread.Sleep(scrollTextSpeed);
}
}
}
protected
override
void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
SizeF stringSize = e.Graphics.MeasureString(text,
this
.Font);
var yPos = (
this
.ClientSize.Height / 2) - (stringSize.Height / 2);
e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; e.Graphics.DrawString(text,
this
.Font, brus, currentPos, yPos);
if
(fisttime)
{
currentPos =
this
.ClientSize.Width - 1;
fisttime =
false
;
}
else
{
if
(currentPos < (-1 * (stringSize.Width)))
currentPos =
this
.ClientSize.Width - 1;
else
currentPos -= scrollPixelDistance;
}
}
Reply
Answers (
3
)
from where i can download Andriod SDK for VS 2015
I need to synchronize two tables sql server using c#