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

My Button is not showing up in C# (Visual Studio Code)

I am trying to add a clickable button on a Form but is not showing up. I am working on Visual Studio Code and I am using the Designers code.

I have tried changing its attributes, size and position but nothing happens, what may be wrong?

    this.components = new System.ComponentModel.Container();
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(400, 620);
    this.StartPosition = FormStartPosition.CenterScreen;
    this.Text = "FORMULARIO";
    this.Controls.Add(label1);
    this.Controls.Add(txtbx1);
    this.Controls.Add(label2);
    this.Controls.Add(txtbx2);
    this.Controls.Add(label3);
    this.Controls.Add(txtbx3);
    this.Controls.Add(label4);
    this.Controls.Add(txtbx4);
    this.Controls.Add(btn);
    
    
    btn = new Button();
    btn.Text = "Submit";
    btn.Location = new Point(400, 100);
    btn.Size = new Size(100, 100);
    btn.BackColor = Color.Gray;
    btn.ForeColor = Color.Yellow;
    btn.Font = new Font("Verdana", 16);
    btn.Click += new EventHandler(Button_Click);

}
private void Button_Click(object sender, EventArgs e)
{
    MessageBox.Show("Thank You! ");
    this.Close();
}
private System.Windows.Forms.Button add;

#endregion

}

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

>Solution :

this.Controls.Add(btn);


btn = new Button();

You are adding btn to Controls collection first. (Whereever you are initializing your btn variable). And then you create new Button(). Try to set up your button before adding to collection.

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