Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollbar on a Label

Tags:

c#

winforms

I need to be able to scroll text on a label i am using this for the credits portion of a tic tac toe game. How can I make this happen we've only been taught to scroll through number values in the scrollbar not text.

 private void xGameCreditsButton_Click(object sender, EventArgs e)
        {
            this.xWinnerLabel.BackColor = Color.White;
            this.xCreditsScrollBar.Visible = true;
            this.xWinnerLabel.Text = "This game was made possible with the help of: blah bla blah";
        }
like image 685
Michael Quiles Avatar asked May 25 '10 16:05

Michael Quiles


People also ask

How do I add a scrollbar to a label?

Place a panel in location where you want the label to be, set it's AutoScroll property to true. Then place the label in the panel, anchor it and set it's AutoSize property to true. This will make the panel provide the scroll bars if the label's text extends outside of the panel.

Can we add scrollbar to label in tkinter?

We can use Tkinter's scrollbar and add it to our text widget. Now, after adding the scrollbar, we should be able to display larger texts properly. To create a scrollbar object, use tk. Scrollbar() and add it to our application!

How do I add a scrollbar in Visual Studio?

Open the Scroll Bars options page by choosing Tools > Options > Text Editor > All Languages > Scroll Bars.


3 Answers

Instead of a Label, use a TextBox and set the ScrollBars, MultiLine and WordWrap properties according to your needs. To disable editing of the TextBox (and, thus, make it behave similar to a label), use the ReadOnly property.

like image 144
Heinzi Avatar answered Sep 23 '22 14:09

Heinzi


Since there may be a reason to not use a text box (not wanting the text to be selectable and copyable for instance) here is another solution that works for me:

Place a panel in location where you want the label to be, set it's AutoScroll property to true. Then place the label in the panel, anchor it and set it's AutoSize property to true. This will make the panel provide the scroll bars if the label's text extends outside of the panel.

You may have to set the MaximumSize for the label if you want the text to only scroll in one direction (set a maximum width size if you want only vertical scrolling or set a maximum height if you want only horizontal scrolling).

like image 22
KAThompson Avatar answered Sep 19 '22 14:09

KAThompson


A read-only scrollable TextBox control will be much easier to use.

If you really want to use a label, you could put the label inside a scrollable Panel control, and set the label's AutoSize property to true.

like image 23
SLaks Avatar answered Sep 19 '22 14:09

SLaks