Windows Form Buttons in C#
I am trying to have a button on my C# windows form with a name "Click Me"
开发者_如何学编程It looks like the button text accepts only the words before the space and ignores the rest. Having: this.button_ClickMe.Text = "Click Me";
Displays my button with text "Click" only.
Any idea why? and is there a work-around??
- Ivar
I suspect the button is just too small. Make it bigger, or make set AutoSize = true
(and place it within a container which has enough space, obviously).
Here's an example which works fine for me:
using System;
using System.Drawing;
using System.Windows.Forms;
public class Test
{
static void Main()
{
Form form = new Form {
Controls = {
new Button {
Text = "Click Me!",
AutoSize = true,
Location = new Point(10, 30)
},
}
};
Application.Run(form);
}
}
(Admittedly this sample works even with AutoSize = false
, so I suspect you've hard-coded the size somewhere... or your font is bigger. With longer text, it only works with AutoSize = true
or a manually specified size.)
Button's too small. Make it slightly bigger. You can (but shouldn't) but as much text as you want on a button, including whole sections of HitchHiker's Guide to the Galaxy. (was testing to see if there was a limit)
Check the width of the button.
精彩评论