views:

61

answers:

3

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
+9  A: 

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.)

Jon Skeet
i feel absolutely dumb right now...thanks a ton!!- ivar
topgun_ivard
+4  A: 

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)

Caladain
+1 for the H2G2 reference ;)
Thomas Levesque
A: 

Check the width of the button.

Sunilk