I am currently working on a little app that scrolls a message across the top of the form - nothing complex however i have ran into a issue where i can not get it to work with a toolstri开发者_如何学Cplabel on my c# winform. I currently have it working by the following method using a normal label but toolstriplabels dont appear to have the .Left option i require to make it scroll. This is the code i am currently using in a timer.
private void timer1_Tick(object sender, System.EventArgs e) {
this.label1.Left = this.label1.Left - 1; if (this.label1.Left + this.label1.Width < 0) { this.label1.Left = this.label1.Width; } }
Does anyone know how i can make this work with a toolstrip label as i would really like this scrolling text on a toolstrip so the user can drag it to where there require?
Thanks
How about something like this:
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
string _labelText = "Hello out there!";
int _scrollOffset = 0;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick( object sender, EventArgs e )
{
string textToDisplay = _labelText.Substring( _scrollOffset++ );
this.toolStripLabel1.Text = textToDisplay;
if ( _scrollOffset > _labelText.Length )
{
_scrollOffset = 0;
}
}
}
}
精彩评论