问题
Basically, I am creating a button in an oval shape. But my button label is too long to display in one line, so I wanted to split it into multiple lines so that the oval button looks good.
How do I enable word wrap on a button?
回答1:
Set the label text on form load and add Environment.Newline as the newline string, like this:
btnOK.Text = "OK" + Environment.NewLine + "true";
回答2:
If you want to set a button's label to multi-line text inside the VS designer, you can click on the "down arrow" at the right of the property field and then you are able to enter multiple lines of text.
I tried this in VS 2015.
回答3:
Just add a newline in the text at the place where it should split.
回答4:
Try to add "\n" to button's Text property in the places you want to wrap.
回答5:
There are two options:
- If you are creating a custom control, then place a label control on it with the
Autosize = true
option. And adjust its size as per the buttons size. - Add a new line wherever you want (a bit crude).
回答6:
You can create custom Button with one additional property (say, Label
) which converts "\n" occurrence into "real" newline (because VS designer cannot do it already 10 years):
public string Label
{
get { return (string.IsNullOrEmpty(Text) ? Text : Text.Replace("\n", @"\n")); }
set {
Text = (string.IsNullOrEmpty(value) ? value : value.Replace(@"\n", "\n"));
}
}
Once you created such class, your SuperButton will be visible in Toolbox at Project page, so you don't loose visual way of design.
回答7:
You just need to insert a line break (i.e. \n) in the button text.
Example:
Button1.AutoSize = true;
Button1.Text = "This is \n The Button Text";
来源:https://stackoverflow.com/questions/2972077/multiline-text-as-the-button-label-in-windows-forms