Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Button gets bigger at runtime as in designer

I have a CustomButton-class and in Designer it looks fine. When i compile my project and watch my form at runtime the buttons are bigger then in designer.

In Designer it looks like this:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

At Runtime it looks like this:

enter image description here

Here my CustomButton-class: (TPButton.cs)

public class TPButton : Button {
    public TPButton() {
        InitializeComponent();
    }

    private void InitializeComponent() {
        this.SuspendLayout();
        // 
        // TPButton
        // 
        this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
        this.Size = new System.Drawing.Size(75, 26);
        this.ResumeLayout(false);

    }
}

And here is my designercode from the view:

partial class EinAusschlussV {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing) {
        if (disposing && (components != null)) {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent() {
        this.tpComboBox1 = new Infrastructure.CustomControls.TPComboBox();
        this.lblIln = new Infrastructure.CustomControls.TPLabel();
        this.tpButton1 = new Infrastructure.CustomControls.TPButton();
        this.tpButton2 = new Infrastructure.CustomControls.TPButton();
        this.SuspendLayout();
        // 
        // tpComboBox1
        // 
        this.tpComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.tpComboBox1.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.tpComboBox1.FormattingEnabled = true;
        this.tpComboBox1.Location = new System.Drawing.Point(45, 11);
        this.tpComboBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
        this.tpComboBox1.Name = "tpComboBox1";
        this.tpComboBox1.Size = new System.Drawing.Size(121, 25);
        this.tpComboBox1.TabIndex = 0;
        // 
        // lblIln
        // 
        this.lblIln.AutoSize = true;
        this.lblIln.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.lblIln.Location = new System.Drawing.Point(12, 14);
        this.lblIln.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
        this.lblIln.Name = "lblIln";
        this.lblIln.Size = new System.Drawing.Size(27, 17);
        this.lblIln.TabIndex = 1;
        this.lblIln.Text = "ILN";
        // 
        // tpButton1
        // 
        this.tpButton1.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.tpButton1.Location = new System.Drawing.Point(172, 10);
        this.tpButton1.Name = "tpButton1";
        this.tpButton1.Size = new System.Drawing.Size(75, 25);
        this.tpButton1.TabIndex = 2;
        this.tpButton1.Text = "tpButton1";
        this.tpButton1.UseVisualStyleBackColor = true;
        // 
        // tpButton2
        // 
        this.tpButton2.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.tpButton2.Location = new System.Drawing.Point(172, 241);
        this.tpButton2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
        this.tpButton2.Name = "tpButton2";
        this.tpButton2.Size = new System.Drawing.Size(75, 26);
        this.tpButton2.TabIndex = 3;
        this.tpButton2.Text = "tpButton2";
        this.tpButton2.UseVisualStyleBackColor = true;
        // 
        // EinAusschlussV
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(660, 497);
        this.Controls.Add(this.tpButton2);
        this.Controls.Add(this.tpButton1);
        this.Controls.Add(this.lblIln);
        this.Controls.Add(this.tpComboBox1);
        this.Margin = new System.Windows.Forms.Padding(4);
        this.Name = "EinAusschlussV";
        this.Text = "EinAusschlussV";
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private TPComboBox tpComboBox1;
    private TPLabel lblIln;
    private TPButton tpButton1;
    private TPButton tpButton2;
}

I don´t know why this happens.

Can anyone help me?

Thanks in advance.

>Solution :

You change the Button-Size in runtime in the InitializeComponent, thus overriding the values specified in the designercode.

Try the InitializeComponent without changeing the properties:

private void InitializeComponent() {
    this.SuspendLayout();
    // 
    // TPButton
    // 
    this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    //this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
    //this.Size = new System.Drawing.Size(75, 26);
    this.ResumeLayout(false);

}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading