Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to give scrolling in textbox?

i have taken a textbox

         <TextBox Height="218" HorizontalAlignment="Stretch" Margin="0,56,0,0" Name="txtBox" VerticalAlignment="Top" TextWrapping="Wrap"
             Text="" GotFocus="txtBox_GotFocus" TextChanged="txtBox_TextChanged" IsTabStop="True" 
             IsEnabled="True" IsHitTestVisible="True" VerticalScrollBarVisibility="Auto" Background="White" FontFamily="Tahoma" />       

Now when i enter lot of text in textbox then text scrolled up automatically. I want to show a scrollbar with which user can surf to the whole text. How to do this.

like image 767
rubyraj Avatar asked May 06 '11 07:05

rubyraj


People also ask

How do I add a scrollable text box in HTML?

Approach: To create a responsive scroll box, add a <div> tag and then proceed to create the scroll box. All you need to do is to choose the height and width of the scroll box (make sure that the height of your box is short enough so that you have an overflow of the text, allowing box to scroll down.

What is a scrolling text box?

An HTML scroll box is a box that grows scroll bars when it's contents are too large to fit in the box. How do you make the box? You create the box using a normal HTML element (such as the div element). Then, to make the box scroll, you apply the CSS overflow property to the div.

How do I scroll text in Word?

Scroll in a DocumentClick the arrow buttons at the top, bottom, and sides of the scroll bar to scroll one line at a time. Click and drag a scroll bar to move quickly though a document, releasing it when you've reached the page you want.


3 Answers

You could use a simple ScrollViewer, like this:

<ScrollViewer Height="219" VerticalScrollBarVisibility="Auto">
    <TextBox  VerticalAlignment="Top" TextWrapping="Wrap" Height="Auto" HorizontalAlignment="Left" Name="textBox1" Text="TextBox" Width="460">

    </TextBox>
</ScrollViewer>

That's in case the text is entered vertically. You could do the same for horizontal scrolling but this method is not quite reliable due to the fact that it doesn't scroll automatically with the default implementation (like I showed).

Generally, I would simply recommend overriding the template for the default control.

like image 93
Den Delimarsky Avatar answered Oct 05 '22 07:10

Den Delimarsky


There isn't a simple solution to this problem. Additionally, if you are allowing someone to enter a large amount of text it's possible that as they add more lines you coudl reach the height limit (2048px) imposed on UIElements.

If you need users to be able to enter a large amount of text you should consider putting an Input element inside a WebBrowser control and using that for the field instead.

like image 30
Matt Lacey Avatar answered Oct 05 '22 07:10

Matt Lacey


Two simple steps to go for this:

  1. Create TextBox_TextInputStart event handler.
  2. assuming your scrollviewer is named as sv and textbox is named as txtbx, add the following lines in the event handler method
 this.sv.UpdateLayout();
 this.sv.ScrollToVerticalOffset(this.txtbx.ActualHeight);
like image 38
Uday0119 Avatar answered Oct 05 '22 09:10

Uday0119