HighTechTalks DotNet Forums  

Getting Cursor to End of a TextBox in Form_Load Fails

Dotnet Framework (WinForms Controls) microsoft.public.dotnet.framework.windowsforms.controls


Discuss Getting Cursor to End of a TextBox in Form_Load Fails in the Dotnet Framework (WinForms Controls) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Freddo
 
Posts: n/a

Default Getting Cursor to End of a TextBox in Form_Load Fails - 03-05-2010 , 08:52 AM






Hi All,

In the Form_Load event, I'm running the following code after populating a
TextBox from a file. The TextBox's MultiLine property is enabled and I have
a vertical scrollbar on this control. This code DOES work if outside of the
Form_Load event if when it's executed "after" the form is loaded.

My question is this: Is there a Form event I can use or am I missing
something regarding an event in the the control itself I should use? Here's
the code:

' Set the cursor to the end of the textbox.
txtScroll.SelectionStart = txtScroll.TextLength
txtScroll.ScrollToCaret() ' Scroll down to the cursor position.

--

Thanks in advance for your help -- it is greatly appreciated!
Kind regards - Fred

Reply With Quote
  #2  
Old   
Herfried K. Wagner [MVP]
 
Posts: n/a

Default Re: Getting Cursor to End of a TextBox in Form_Load Fails - 03-05-2010 , 07:48 PM






Am 05.03.2010 15:52, schrieb Freddo:
Quote:
In the Form_Load event, I'm running the following code after populating
a TextBox from a file. The TextBox's MultiLine property is enabled and I
have a vertical scrollbar on this control. This code DOES work if
outside of the Form_Load event if when it's executed "after" the form is
loaded.

My question is this: Is there a Form event I can use or am I missing
something regarding an event in the the control itself I should use?
Here's the code:

' Set the cursor to the end of the textbox.
txtScroll.SelectionStart = txtScroll.TextLength
txtScroll.ScrollToCaret() ' Scroll down to the cursor position.
Did you already try to place the 'ScrollToCaret' call in the form's
'Shown' event?

In addition, take a look at this alternative method:

Scrolling the textbox control to top or bottom
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=textboxscroll&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Reply With Quote
  #3  
Old   
Freddo
 
Posts: n/a

Default Re: Getting Cursor to End of a TextBox in Form_Load Fails - 03-08-2010 , 09:18 AM



Hi Herfried,

I thought I completely exhausted the list of form event handlers but somehow
overlooked "Form.Shown!" Thanks for pointing this one out to me - it worked
perfectly!

Kind regards - Fred

###

"Herfried K. Wagner [MVP]" <hirf-spam-me-here (AT) gmx (DOT) at> wrote

Quote:
Am 05.03.2010 15:52, schrieb Freddo:
In the Form_Load event, I'm running the following code after populating
a TextBox from a file. The TextBox's MultiLine property is enabled and I
have a vertical scrollbar on this control. This code DOES work if
outside of the Form_Load event if when it's executed "after" the form is
loaded.

My question is this: Is there a Form event I can use or am I missing
something regarding an event in the the control itself I should use?
Here's the code:

' Set the cursor to the end of the textbox.
txtScroll.SelectionStart = txtScroll.TextLength
txtScroll.ScrollToCaret() ' Scroll down to the cursor position.

Did you already try to place the 'ScrollToCaret' call in the form's
'Shown' event?

In addition, take a look at this alternative method:

Scrolling the textbox control to top or bottom
URL:http://dotnet.mvps.org/dotnet/faqs/?id=textboxscroll&lang=en

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/
V B <URL:http://dotnet.mvps.org/dotnet/faqs/

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.