Reputation: 2066
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?
Upvotes: 16
Views: 65891
Reputation: 1
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";
Upvotes: 0
Reputation: 821
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.
Upvotes: 40
Reputation: 179
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.
Upvotes: 0
Reputation: 11644
There are two options:
Autosize = true
option. And adjust its size as per the buttons size.Upvotes: 0
Reputation: 30873
Just add a newline in the text at the place where it should split.
Upvotes: 3
Reputation: 2023
Set the label text on form load and add Environment.Newline as the newline string, like this:
btnOK.Text = "OK" + Environment.NewLine + "true";
Upvotes: 31
Reputation: 8694
Try to add "\n" to button's Text property in the places you want to wrap.
Upvotes: 1