tags:

views:

113

answers:

4

I have very long text and put it into TextBox. I want to display automatically the beginning of the text not the end. But TextBox automatically show the end of my text.

What can I do to achieve it.

I use SelectionStart method to put cursor at the beginning of text in TextBox in order to implement some simple IntelliSense so preferred solution would not use methods that move cursor.

+1  A: 
kbrimington
It works the same as textBox.Text
Darqer
@Darqer - Sure enough. Interestingly, it worked as described from the form constructor. I've updated my post with an alternative.
kbrimington
+1  A: 

You could always initially put a smaller value in the textbox then upon your criteria for displaying the full text append the remaining portion of the full text.

Example:

textBox.text = someString.Substring(0, x);

then when needed do

textBox.AppendText(someString.Substring(x+1));
Jamie Altizer
+1  A: 

You could use owner-draw to override the rendering of the textbox when it doesn't have the input focus. That would trivially give you complete control of what it shows when, without breaking any of the actual editing functionality of the textbox by trying to hack it.

Jason Williams
+1  A: 

You can send a Win32 scroll message to the underlying textbox handle via P/Invoke:

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);

// From User32.dll
private const int WM_VSCROLL = 277;
private const int SB_TOP = 6;

SendMessage(yourTextBox.Handle, WM_VSCROLL, (IntPtr)SB_TOP, IntPtr.Zero);
Dour High Arch