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";
}
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.
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!
Open the Scroll Bars options page by choosing Tools > Options > Text Editor > All Languages > Scroll Bars.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With