das form hat 3 elemente: textBox1, label1, timer1.
gesteuert werden die zeiten über
tickerCharMS: ms für die einzelnden buchstaben
tickerNewLineMS: ms die für eine newline gewartet werden.
tickerCharMS soll sich ja pro zeile um 1 erhöhen.
um einen effekt zu bemerken habe ich den um jeweils 50 erhöht.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace laufschrift {
public partial class Form1 : Form {
public Form1 () {
InitializeComponent ();
this.timer1.Enabled = false;
}
private String[] tickerText;
private int tickerTextIndex;
private int tickerCharIndex;
private int tickerCharMS;
private int tickerNewLineMS;
private void initTimer () {
this.tickerText = this.textBox1.Text.Trim ().Split (new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
this.tickerTextIndex = 0;
this.tickerCharIndex = 0;
this.label1.Text = "";
this.tickerCharMS = 41;
this.tickerNewLineMS = 1000;
this.timer1.Interval = this.tickerCharMS;
this.timer1.Enabled = true;
}
private void button1_Click (object sender, EventArgs e) {
this.label1.Text = "";
if (this.textBox1.Text.Trim ().Length > 0) {
this.initTimer ();
this.button1.Enabled = false;
}
}
private bool wasNewLine = false;
private void timer1_Tick (object sender, EventArgs e) {
if (this.wasNewLine) {
this.timer1.Interval = this.tickerCharMS + this.tickerTextIndex*50;
this.wasNewLine = false;
}
string s = this.tickerText[this.tickerTextIndex];
char c = s.ElementAt (this.tickerCharIndex);
this.label1.Text += c;
if (this.tickerCharIndex + 1 < s.Length) {
this.tickerCharIndex++;
}
else {
this.tickerCharIndex = 0;
if (this.tickerTextIndex + 1 < this.tickerText.Length) {
this.label1.Text += "\r\n";
this.tickerTextIndex++;
this.timer1.Interval = this.tickerNewLineMS;
this.wasNewLine = true;
}
else {
this.timer1.Enabled = false;
this.button1.Enabled = true;
}
}
}
}
}