0

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

4
  • 1
    Are you talking about design time in the IDE when controls are initially created?
    – Paul Sasik
    Apr 7, 2010 at 17:48
  • @Paul Sasik: yup I want every button created with certain width and height
    – Luiscencio
    Apr 7, 2010 at 17:49
  • So for example: You drag a button onto a Form surface from the toolbox and instead of the default 23x80 (roughly) you might want 50x50 when the control appears. Btw, it feels like you're about to do a lot of work to avoid/automate something that is not that time-consuming to do in the IDE.
    – Paul Sasik
    Apr 7, 2010 at 17:52
  • Possible duplicate of C# - Common way to format listview controls on forms? Mar 3, 2016 at 10:05

4 Answers 4

0

See this question. Should explain it...

0

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.

0

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.