Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to create a scrolling marquee in the title bar of a visual studio form and I know it can be done in like 2 lines of code using the length property of the string I want scrolling in the titlebar but can't seem to figure it out.

What I have tried:

while loop, it just breaks the program for some reason
this.Text= something with Length
Posted
Updated 10-Dec-21 4:06am

GUI programs aren't like Console: they operate by receiving and processing messages like "this button was clicked", "this needs to be drawn", "this timer has gone off" and by running short pieces of code which process those messages - or events - and do something as a result of the button press, the screen redraw, the timer ticking along.
In short, GUI apps respond to user activity.

That's not what happens with console apps: they tell the user what to do, and wait until he has done it. They aren't responsive, they are procedural - they set what happens and when it happens.

So when you write a loop (particularly a long loop) in a message / event handler nothing else can happen until that loop has finished. That means the display doesn't get updated, the mouse no longer has any effect on anything, and so on.
That's not "broken", that is the way it is supposed to work! You spend too long doing something, you app freezes until you let it continue. If you have a long job to do, you do it on a separate thread - but then you can't access display controls!

To make a marquee in the title, you would need to add a Timer to your app, and move the Marquee a little bit each time it ticked, with no loop at all!
But to be honest, a basic marquee moving character by character is going to look terrible, and a "proper marquee" moving pixel by pixel is probably outside you skill set if you don't yet understand how the system works at all! It's not a easy thing to do at all, though this may help: WinForm Extended[^] Do bear in mind that different OSes do different things to system-handled components such as titles, so the example I gave you may not work with modern OSes or may stop working at any point with an update!
 
Share this answer
 
It took me seconds to find this scrolling text in title bar C#[^]
Don't use a While loop as you won't be able to do anything else. Use a Timer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900