Hi, Experts
I want to create a auto scroll Textbox in C#. But I dont know how to make text box scroll by coding.
Please, help me.
Printable View
Hi, Experts
I want to create a auto scroll Textbox in C#. But I dont know how to make text box scroll by coding.
Please, help me.
you could do it with API:Code://add this
using System.Runtime.InteropServices;
//then the code is:
public partial class Form1 : Form
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
const int EM_LINESCROLL = 0xB6;
public Form1()
{
InitializeComponent();
for (int n = 0; n < 20; n++)
{
textBox1.Text += (n.ToString() + Environment.NewLine);
}
}
private void button1_Click(object sender, EventArgs e)
{
// scroll up
SendMessage(textBox1.Handle, EM_LINESCROLL, IntPtr.Zero, (IntPtr)(-1));
}
private void button2_Click(object sender, EventArgs e)
{
// scroll down
SendMessage(textBox1.Handle, EM_LINESCROLL, IntPtr.Zero, (IntPtr)1);
}
}
I believe.. because John has said it 3,793 times.. that.. if you use append text it autoscrolls to where the text is.. if that's what you want