473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

TextBox auto scroll to end when text is added

Hello,

textBox += someData + "\r\n";
does not scroll the visible text to the end. How do I perform that ?

Also this way seems to me a lot of reallocating memory. Is there better way
to add text to a textbox ?

--
rgds, Wilfried
http://www.mestdagh.biz
Nov 16 '05 #1
5 30969
Howdy just came accross this myself
if you use appendtext this should do the trick, as long as the textbox has
focus,
here is my solution, i used a richtextbox because i wanted to use some of
it's additional reatures, but basically i send the richtextbox a scroll
message,
usage
/// <summary>
/// Adds some status information
/// </summary>
/// <param name="strInfo"></param>
public void AddStatusInfo(string strInfo)
{
tbStatus.AppendText(strInfo);
ScrollTextBoxEnd(tbStatus);
}

#region Native

/// <summary>
/// Scrolls the textbox to the end
/// </summary>
/// <param name="tb"></param>
private void ScrollTextBoxEnd(RichTextBox tb)
{
const int WM_VSCROLL = 277;
const int SB_BOTTOM = 7;

IntPtr ptrWparam = new IntPtr(SB_BOTTOM);
IntPtr ptrLparam = new IntPtr(0);
SendMessage(tb.Handle, WM_VSCROLL, ptrWparam, ptrLparam);
}
[DllImport("User32.dll", CharSet=CharSet.Auto, EntryPoint="SendMessage")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
#endregion

#endregion //Private

"Wilfried Mestdagh" wrote:
Hello,

textBox += someData + "\r\n";
does not scroll the visible text to the end. How do I perform that ?

Also this way seems to me a lot of reallocating memory. Is there better way
to add text to a textbox ?

--
rgds, Wilfried
http://www.mestdagh.biz

Nov 16 '05 #2
Howdy just came accross this myself
if you use appendtext this should do the trick, as long as the textbox has
focus,
here is my solution, i used a richtextbox because i wanted to use some of
it's additional reatures, but basically i send the richtextbox a scroll
message,
usage
/// <summary>
/// Adds some status information
/// </summary>
/// <param name="strInfo"></param>
public void AddStatusInfo(string strInfo)
{
tbStatus.AppendText(strInfo);
ScrollTextBoxEnd(tbStatus);
}

#region Native

/// <summary>
/// Scrolls the textbox to the end
/// </summary>
/// <param name="tb"></param>
private void ScrollTextBoxEnd(RichTextBox tb)
{
const int WM_VSCROLL = 277;
const int SB_BOTTOM = 7;

IntPtr ptrWparam = new IntPtr(SB_BOTTOM);
IntPtr ptrLparam = new IntPtr(0);
SendMessage(tb.Handle, WM_VSCROLL, ptrWparam, ptrLparam);
}
[DllImport("User32.dll", CharSet=CharSet.Auto, EntryPoint="SendMessage")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
#endregion

#endregion //Private

"Wilfried Mestdagh" wrote:
Hello,

textBox += someData + "\r\n";
does not scroll the visible text to the end. How do I perform that ?

Also this way seems to me a lot of reallocating memory. Is there better way
to add text to a textbox ?

--
rgds, Wilfried
http://www.mestdagh.biz
"Wilfried Mestdagh" wrote:
Hello,

textBox += someData + "\r\n";
does not scroll the visible text to the end. How do I perform that ?

Also this way seems to me a lot of reallocating memory. Is there better way
to add text to a textbox ?

--
rgds, Wilfried
http://www.mestdagh.biz

Nov 16 '05 #3
Howdy just came accross this myself
if you use appendtext this should do the trick, as long as the textbox has
focus,
here is my solution, i used a richtextbox because i wanted to use some of
it's additional reatures, but basically i send the richtextbox a scroll
message,
usage
/// <summary>
/// Adds some status information
/// </summary>
/// <param name="strInfo"></param>
public void AddStatusInfo(string strInfo)
{
tbStatus.AppendText(strInfo);
ScrollTextBoxEnd(tbStatus);
}

#region Native

/// <summary>
/// Scrolls the textbox to the end
/// </summary>
/// <param name="tb"></param>
private void ScrollTextBoxEnd(RichTextBox tb)
{
const int WM_VSCROLL = 277;
const int SB_BOTTOM = 7;

IntPtr ptrWparam = new IntPtr(SB_BOTTOM);
IntPtr ptrLparam = new IntPtr(0);
SendMessage(tb.Handle, WM_VSCROLL, ptrWparam, ptrLparam);
}
[DllImport("User32.dll", CharSet=CharSet.Auto, EntryPoint="SendMessage")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
#endregion

#endregion //Private

"Wilfried Mestdagh" wrote:
Hello,

textBox += someData + "\r\n";
does not scroll the visible text to the end. How do I perform that ?

Also this way seems to me a lot of reallocating memory. Is there better way
to add text to a textbox ?

--
rgds, Wilfried
http://www.mestdagh.biz

Nov 16 '05 #4
Howdy just came accross this myself
if you use appendtext this should do the trick, as long as the textbox has
focus,
here is my solution, i used a richtextbox because i wanted to use some of
it's additional reatures, but basically i send the richtextbox a scroll
message,
usage
/// <summary>
/// Adds some status information
/// </summary>
/// <param name="strInfo"></param>
public void AddStatusInfo(string strInfo)
{
tbStatus.AppendText(strInfo);
ScrollTextBoxEnd(tbStatus);
}

#region Native

/// <summary>
/// Scrolls the textbox to the end
/// </summary>
/// <param name="tb"></param>
private void ScrollTextBoxEnd(RichTextBox tb)
{
const int WM_VSCROLL = 277;
const int SB_BOTTOM = 7;

IntPtr ptrWparam = new IntPtr(SB_BOTTOM);
IntPtr ptrLparam = new IntPtr(0);
SendMessage(tb.Handle, WM_VSCROLL, ptrWparam, ptrLparam);
}
[DllImport("User32.dll", CharSet=CharSet.Auto, EntryPoint="SendMessage")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
#endregion

#endregion //Private

"Wilfried Mestdagh" wrote:
Hello,

textBox += someData + "\r\n";
does not scroll the visible text to the end. How do I perform that ?

Also this way seems to me a lot of reallocating memory. Is there better way
to add text to a textbox ?

--
rgds, Wilfried
http://www.mestdagh.biz
"Wilfried Mestdagh" wrote:
Hello,

textBox += someData + "\r\n";
does not scroll the visible text to the end. How do I perform that ?

Also this way seems to me a lot of reallocating memory. Is there better way
to add text to a textbox ?

--
rgds, Wilfried
http://www.mestdagh.biz

Nov 16 '05 #5
thx :)
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alex Moskalyuk | last post by:
I am using System.Windows.Forms.TextBox to publish some real-time data that's coming off the external devices. My data is fed into the TextBox with proper precautions not to exceed the MaxSize...
2
by: JonnyT | last post by:
I searched high and low for an answer on how to auto scroll a richtextbox and now I finally have it. Since it took me a while to get a good efficient way of doing it that didn't require focus to...
4
by: iwdu15 | last post by:
hi, i have a web browser control on my win form, and every so often i add text to it. when the text goes beyond the last line, the control doesnt auto scroll to show it and there is no property...
3
by: plonk | last post by:
Hi I have a teeny problem that I cannot solve. I load HTML Source into a textbox and have a "find' button that searches through the text using the Instr Function, and highlights the result...
2
by: eddwinpaz | last post by:
Hi everyone..!! i have a chat and i want all the new messages to be seen but ecause i have a css iframe i would like to auto scroll down. so i can see the new message instead of click the scroller...
0
by: gobblegob | last post by:
Well i cannont remember where i picked this code up, but i have seen it asked for in many forums, Many times so i thought i'd add it here (Since this is my favourite forum). Auto scroll text in...
4
by: Pubs | last post by:
Hi all, I have application being written in C# where I have to calculate the text pixel height and width of the line being typed in rich text box. I need to get the pixel height of the character...
3
by: TS | last post by:
I am using IE 7. I have a website running on my local machine (localhost) and auto complete doesnt work for any of the textboxes, but going to web sites on the internet does support this so i know...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.