The Demo code is as follows:
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;
Namespace WindowsApplication27
{
/** // <Summary>
/// Demonstrate how to scroll the text loop in TextBox:
/// </Summary>
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
This. textBox1.Clear ();
For (int I = 0; I <= 20; I ++)
{
This. textBox1.Text + = string. Format ("{0}: jinjazz __{ 1}", I, I );
}
This. timer1.Interval = 200;
This. timer1.Start ();
}
// Send a message
[DllImport ("user32.dll", EntryPoint = "SendMessage")]
Public static extern int SendMessage (IntPtr hWnd, int wMsg, int wParam, int lParam );
// Obtain the position of the scroll bar
[DllImport ("user32")]
Public static extern int GetScrollPos (IntPtr hwnd, int nBar );
// Set the scroll bar position
[DllImport ("user32.dll")]
Static extern int SetScrollPos (IntPtr hWnd, int nBar,
Int nPos, bool bRedraw );
Public const int EM_LINESCROLL = 0xb6;
Private void timereffectick (object sender, EventArgs e)
{
Int I = GetScrollPos (this. textBox1.Handle, 1 );
// Scroll down a row
SendMessage (this. textBox1.Handle, EM_LINESCROLL, 0, 1); // indicates vertical scroll down
// Determine whether there is any location change. If not, it indicates that it is at the bottom and returns the start point.
If (I = GetScrollPos (this. textBox1.Handle, 1 ))
{
// Return to the top. It seems that there is a problem with SetScrollPos. the scroll bar and text are not synchronously updated.
This. textBox1.SelectionStart = 0;
This. textBox1.SelectionLength = 1;
This. textBox1.ScrollToCaret ();
This. textBox1.SelectionLength = 0;
}
Console. WriteLine (I );
}
Private void textbox#mouseenter (object sender, EventArgs e)
{
This. timer1.Stop ();
}
Private void textBox1_MouseLeave (object sender, EventArgs e)
{
This. timer1.start ();
}
}
}