C#

[C#]Scrolling Text 예제

선영아 사랑해 2018. 4. 19. 16:01


  string strText = "";

        string strData = "";


        private void ScrollingForm_Load(object sender, EventArgs e)
        {
            strText = textBox1.Text;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;

            for (int k = 1; k < strData.Length; k++)
            {
                textBox1.Text = strData.Substring(k);

                textBox1.Refresh();

                System.Threading.Thread.Sleep(500);

                Application.DoEvents();
            }

            timer1.Enabled = true;
        }

        
        private void ScrollingForm_Activated(object sender, EventArgs e)
        {
            for (int i = 0; i <= strText.Length; i++)
            {
                if (i == strText.Length)
                {
                    textBox1.Text = strText.Substring(i) + string.Format("{0, -30}", "") + strText.Substring(0);

                    strData = textBox1.Text;
                }
                else
                    textBox1.Text = strText.Substring(i);

                textBox1.Refresh();

                System.Threading.Thread.Sleep(500);

                Application.DoEvents();
            }

            timer1.Interval = 1000;
            timer1.Enabled = true;
        }