Scrollbar on a Label
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.Visib开发者_StackOverflowle = true;
this.xWinnerLabel.Text = "This game was made possible with the help of: blah bla blah";
}
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 it doesn't absolutely have to be a label, you could make this a read-only multi-line edit field instead. The edit control will scroll automatically.
精彩评论