Sprache: C#
Create a simple ticker using a label
// Designer
this.label1 = new System.Windows.Forms.Label();
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Text = "Hello World!";
private void Form1_Load(object sender, System.EventArgs e)
{
Timer t1 = new Timer();
t1.Interval = 20;
t1.Tick+=new EventHandler(t1_Tick);
t1.Start();
}
private void t1_Tick(object sender, EventArgs e)
{
int i;
i = label1.Location.X;
if (i >= this.Width)
i = 0;
else
i = label1.Location.X + 1;
label1.Location = new Point(i,0);
}
// Designer
this.label1 = new System.Windows.Forms.Label();
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Text = "Hello World!";
private void Form1_Load(object sender, System.EventArgs e)
{
Timer t1 = new Timer();
t1.Interval = 20;
t1.Tick+=new EventHandler(t1_Tick);
t1.Start();
}
private void t1_Tick(object sender, EventArgs e)
{
int i;
i = label1.Location.X;
if (i >= this.Width)
i = 0;
else
i = label1.Location.X + 1;
label1.Location = new Point(i,0);
}
Alte URL:
/snippet/create-a-simple-ticker/212
Keine optimale Lösung, das Label scrollt nach rechts, anstatt in die Leserichtung, und das Label klebt ganz nach oben in der Form, und was hat die Variable i da zu suchen?
[code]
private void t1_Tick(object sender, EventArgs e)
{
if (label1.Location.X == -label1.Size.Width)
label1.Location = new Point(this.Size.Width, label1.Location.Y);
label1.Location = new Point(label1.Location.X-1, label1.Location.Y);
}
[/code]