consolecontrol icon indicating copy to clipboard operation
consolecontrol copied to clipboard

Support Scroll to Bottom

Open dwmkerr opened this issue 12 years ago • 5 comments

(NB Thanks VisualG at CodeProject, see http://www.codeproject.com/Articles/335909/Embedding-a-Console-in-a-C-Application?msg=4642047#xx4642047xx)

This responce is a little late i know, but there are probably more people that want to know how to do this.

if u want the richtextbox to auto scroll down when text is appended u can use this code

[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr window, int message, int wparam, int lparam);

private const int SbBottom = 0x7;
private const int WmVscroll = 0x115;


//call this in a method after appending text in the richtextbox
//dont forget to change richtextbox1 with youre richtextboxcontrol

SendMessage(richtextbox1.Handle, WmVscroll, SbBottom, 0x0);

dwmkerr avatar Aug 30 '13 17:08 dwmkerr

In WPF, all you need to do is add

richTextBoxConsole.ScrollToEnd();

into ConsoleControl.xaml.cs after appending the text inside WriteOutput().

joelspadin avatar Dec 08 '13 22:12 joelspadin

I guess this is dead, however for the future reference of anybody thinking to use this component with the fix suggested here I can warn you: it is hideously slow. It takes about 2 minutes to add 5000 lines to console if you also perform ScrollToEnd after each one.

billw2012 avatar Apr 25 '17 17:04 billw2012

I know this is probably even more dead than when the last poster commented but I discovered a simple way to auto scroll even in Windows Forms. Within the onConsoleOutput event on the control, just add the lines: ConsoleControl.ConsoleControl console = sender as ConsoleControl.ConsoleControl; console.InternalRichTextBox.ScrollToCaret(); This worked fine for me and didn't seem to have much of an effect on performance. However if the lines are coming very thick and fast you could do the scroll every so many event triggers rather than each one.

ashleyemery avatar Jul 25 '17 23:07 ashleyemery

Thanks for the tip @ashleyemery, hopefully this'll help anyone who has the same problem. I'm unlikely to have the time to add this, but am open to PRs!

dwmkerr avatar Aug 12 '17 13:08 dwmkerr

I know its too late. But if someone finds it helfull add this inside your form [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr window, int message, int wparam, int lparam); call this via SendMessage(consoleControl1.InternalRichTextBox.Handle, WmVscroll, SbBottom, 0x0); where consoleControl1 is the name of your consoleControl

sainsaji avatar Sep 13 '23 11:09 sainsaji