4
votes

On a Winform C# application, i display a textbox on my form. This textbox will display one line, just one. I would like to show and be abe to use an horizontal scrollbar.

I set the property "scrollbar" to horizontal : ScrollBar doesn't show. I add WordWrap to false : ScrollBar doesn't show. I add MultiLine to true ( even if one ligne ) : ScrollBar doesn't show.

My line displayed is a loter "longer" than the contrĂ´le, so i really need a scrollbar :(

Here is the definition :

        this.TxtBox_ApercuFichier.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.TxtBox_ApercuFichier.Location = new System.Drawing.Point(11, 30);
        this.TxtBox_ApercuFichier.Multiline = true;
        this.TxtBox_ApercuFichier.Name = "TxtBox_ApercuFichier";
        this.TxtBox_ApercuFichier.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
        this.TxtBox_ApercuFichier.Size = new System.Drawing.Size(702, 21);
        this.TxtBox_ApercuFichier.TabIndex = 12;

Even with wordwrap at false, it's the same result. ( My textbox is in a groupbox).

Any idea please ?

Thanks a lot :)

Regards,

2
WordWrap to true should work. The Height should be larger than 21 pixels though. - LarsTech
WordWrap is already to true. I replace 21 by 25,same result :-( Maybe due to the groupbox? - Walter Fabio Simoni
To be clear: The scrollbar doesn't show even though your current text is longer? Also: If you want to display only one line, why set multiline=true?? - TaW
How big is the GroupBox? - LarsTech

2 Answers

16
votes

You need to do the following to get a horizontal scroll bar to display in a windows forms text box:

this.TxtBox_ApercuFichier.Multiline = true;
this.TxtBox_ApercuFichier.WordWrap = false;
this.TxtBox_ApercuFichier.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;

You can then resize the text box to give the appearance of one line. You need to have Multiline enabled otherwise the height of the text box will be set to the text height (I can't seem to find an easy way to override this), hence you not being able to see the scroll bar.

0
votes

The following code will set ScrollBar not visible and also the parent panel where its contained.

HScrollBar hScroller = textBox.HScrollBar;
hScroller.Visible = false;  
hScroller.Parent.Visible=false;