SendMessage(pipeTextBox.Handle, WM_VSCROLL, (
IntPtr)SB_BOTTOM, IntPtr.Zero);Textbox scroll to caret
please see code, Im trying to dynamically add three text boxes to a tabpage, i need each texbox to scroll down to the end of the page as text from a pipestream comes in, currently only the last textbox being created will do this so i presume something is being overwrote in memory but im not sure how to do tell each textbox to follow the same routine
lukePosted Oct 10, 2011, 9:03 AM
slightly changed approach once each textbox is dynamically created (read in from text file and iterated over) and added to a tab, am now calling an event handler with the following code, again only the textbox in the last tab (last entry read in from text file) will scroll down as text is read in all the others just remain at the top of the page and the scrollbar gets larger and i can scroll to the bottom but it isnt done automatically, is this enough info to give any advice?
private void pipeTextBox_TextChanged(object sender, EventArgs e)Control c = (Control)sender;
{
pipeTextBox.Focus();
pipeTextBox.SelectionStart = pipeTextBox.Text.Length;
pipeTextBox.ScrollToCaret();
}
public void createPipes()
{
foreach (DictionaryEntry de in pipeNames)
{
TabPage tab = new TabPage(de.Value.ToString());
pipeTextBox = new TextBox()
pipeTextBox.Name = de.Value.ToString() +
pipeTextBox.Width = 630;
pipeTextBox.Height = 470;
pipeTextBox.Multiline = true;
pipeTextBox.AcceptsReturn = true;
pipeTextBox.WordWrap = false;
pipeTextBox.ScrollBars = scrollbars.both;
pipeTextBox.ReadOnly = true
pipeTextBox.TextChanged += new System.EventHandler(this.pipeTextBox_TextChanged);
tab.Controls.Add(pipeTextBox);
PipeServer srv = new PipeServer(de.Value.ToString(), _uiSyncContext, ref temp);
pipeServers[de.Value.ToString()] = srv;
Control temp = pipeTextBox;
}
}
} }
Sam HobbsPosted Oct 8, 2011, 12:13 AM
So I hope you try using ScrollToCaret as Javeed suggests and that you will look for functions such as that in .Net that you can use instead of using the Windows API directly.
There are many great reasons to use the Windows API directly but .Net makes it unnecessary for most things.
Javeed M ShaikhPosted Oct 7, 2011, 12:18 PM
textbox1.ScrollToEnd();
or
textbox1.Select(textbox1.Text.Length, 0);
lukePosted Oct 7, 2011, 12:00 PM
Javeed M ShaikhPosted Oct 7, 2011, 11:31 AM
example would be:
TextBox1.ScrollToCaret();
What is the error you are getting?