0

我试图将其转换为用户控件,以便我可以在我的应用程序中将其用作标准组件。

我想要一些参数,即显示每个项目的时间以及字符串数组设置。

我只需要在表单的某处显示自定义标签

 public void rotateMarqueText(string text)

{
    string[] result = text.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

    new Task(() =>
    {
        int i = result.Count();
        while (true)
        {
            i++;
            if (i > result.Count()) i = 0;
            Task.Factory.StartNew(() =>
            {
                this.Invoke(new Action(() => DisplayText(result[i]))); // 
            });
            Thread.Sleep(1000); // want to param this
        }
    }).Start();
}
private void DisplayText(string x)
{
    marqueText.Text = x;
    marqueText.Refresh();
}

我对用户控件和线程一无所知,我该从哪里开始?

4

1 回答 1

0
public partial class marqueText : UserControl
{

    private Color colFColor;
    private Color colBColor;
    private int timeDelay = 1;
    private string[] scrollText = new string[] { "" };
    private int scrollTextCount;
    private int scrollTextCurrentPosition;

    public marqueText()
    {
        InitializeComponent();
        scrollTextCurrentPosition = 0;
        scrollTextCount = MarqueText.Count();
    }

    public void timer1_Tick(object sender, EventArgs e)
    {
            lblDisplay.Text = scrollText[scrollTextCurrentPosition];
            scrollTextCurrentPosition++;
            if (scrollTextCurrentPosition == scrollTextCount)
            {
                scrollTextCurrentPosition = 0;
            }
    }


    public int MarqueTimeDelay
    {
        get
        {
           return timeDelay;
        }
        set
        {
            timeDelay = value;
            this.timer1.Interval = value * 1000;
        }
    }

    public string[] MarqueText
    {
        get
        {
            scrollTextCount = scrollText.Count();
            return scrollText;
        }
        set
        {
            scrollTextCurrentPosition = 0;
            scrollText = value;
            scrollTextCount = scrollText.Count();
        }
    }

    public Color MarqueBackColor
    {
        get
        {
            return colBColor;
        }
        set
        {
            colBColor = value;
            lblDisplay.BackColor = colBColor;
        }
    }

    public Color MarqueForeColor
    {
        get
        {
            return colFColor;
        }
        set
        {
            colFColor = value;
            lblDisplay.ForeColor = colFColor;
        }
    }
}

似乎与 Timer 一起工作得很好。

于 2013-08-04T16:57:02.713 回答