RichTextBox horizontal scroll not working
Asked Answered
S

5

9

I have a single line readOnly RichTextBox with wordWrap disabled, and I add programmatically one single very long line of text.

However the horizontal scrollBar does not apear, even if I set ScrollBars to ForcedHorizontal.

How can I fix this?

I can navigate through the whole line if i use the arrow keys on the keyboard, but this only makes things worse.

Seaddon answered 17/8, 2012 at 12:29 Comment(2)
When I use a RichTextBox and give it a long string of text with WordWrap=false, I see the horizontal scrollbar automatically. With ForcedHorizontal, do you see the greyed out scrollbar when there is no text? Sanity check, is the bottom of the text box possibly cut off?Pap
No, apparently with RichTextBox scrollbars only work with multilineSeaddon
G
4

I can reproduce this behaviour with

MultiLine = false

If I change this property to True the scrollbar appears as expected

Gensmer answered 17/8, 2012 at 12:36 Comment(3)
This works, but my text has just one line, why should multiline be necessarily?Seaddon
No horizontal scrollbar in non multiline mode...thats oddElaterium
@Reniuz, yes, it's a mystery. It is stated here without much explanation msdn.microsoft.com/en-us/library/aa983606(v=VS.71).aspxGensmer
I
12

Try to solve it with

    Multiline = True
    WordWrap = False

Change this properties to allow the multiline feature and also allow Horizontal scrolling

Immovable answered 14/5, 2013 at 8:3 Comment(3)
For your information even these will not work if your line is all blank space. Lets assume you have 1464 characters and your RichTextBox should display a fraction of it like 100 characters. If the line is all blank space the horizontal scrollbar will not show even with ForcedHorinzontal. Try it and add let say 1 at the end of the line and the scrollbar will show up by magic. I triple test this and it's really true. I even tried having 5 characters at the beginning, then all blank spaces until the end and no scrollbar but as soon as I type a character at the end the scrollbar appears.Calhoun
If so, it's must be a bug with the default RichTextBox. If you want it to work with white spaces only in the end of the line, inherit the default RichTextBox and fix it by your own.Immovable
in our case it's not a problem because we don't need the scrollbar. I wrote to mention it in case people would not understand the reason why they still don't have the scrollbar. Hope this helps othersCalhoun
G
4

I can reproduce this behaviour with

MultiLine = false

If I change this property to True the scrollbar appears as expected

Gensmer answered 17/8, 2012 at 12:36 Comment(3)
This works, but my text has just one line, why should multiline be necessarily?Seaddon
No horizontal scrollbar in non multiline mode...thats oddElaterium
@Reniuz, yes, it's a mystery. It is stated here without much explanation msdn.microsoft.com/en-us/library/aa983606(v=VS.71).aspxGensmer
M
0

I was facing the issue with vertical scroll Bar. If Rich textbox is inside any control like TabPage etc, than in that situation you need to set dock == fill for the RickTextbox.

Martinelli answered 20/4, 2018 at 10:54 Comment(0)
S
0

You have to Set the Multiline property to true. Check this text from MSDN:

To display scroll bars in a RichTextBox control Set the Multiline property to true. No type of scroll bar, including horizontal, will display if the Multiline property is set to false.

Set the ScrollBars property to an appropriate value of the RichTextBoxScrollBars enumeration.

Shalne answered 23/5, 2019 at 12:46 Comment(0)
E
0

This worked for me:

WordWrap = false;
ScrollBars = RichTextBoxScrollBars.Both;
Ensure answered 14/2, 2021 at 23:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.