Hello World

C#(WINFORM, WINCE, WINDOWS MOBILE) 실전 활용 예제소스 및 프로그램 개발

[C#]Scrolling Text 예제

댓글 0

C#

2018. 4. 19.


  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;
        }