views:

45

answers:

4

How can I change for example default width and height for buttons, etc?

A: 

You can inherit from the control and create your own version of it with your own defaults. See DefaultValueAttribute, and be sure to set the values in your constructor.

Jon B
A: 

If you skip the IDE designer and create your own controls programmatically then you can set those controls to any size you wish.

You may want to do this when you have a huge number of controls in your Form and managing them via the designer would become counterproductive. For example, if you were to create a 2D array of buttons at 10x10 = 100 buttons for game or something. In that case it would be better to write a loop that creates those objects in your load handler rather than trying to place them by hand in the designer.

Paul Sasik
+1  A: 

See this question. Should explain it...

Asher
A: 

Create user controls that inherit the controls you want to modify and than change the default properties.

For example, I just crated a custom control that inherits from the Button class and in the constructor I've set the Width and Height properties to 64...

public partial class CustomButton : Button
{
    public CustomButton()
    {
        InitializeComponent();
        this.Height = 64;
        this.Width = 64;
    }        
}

Then I added this custom button to the main form in my winforms application as such:

        CustomButton cb1 = new CustomButton();
        cb1.Location = new Point(120, 450);
        cb1.Parent = this;

As expected, the new button size was 64*64...

kzen