How can I create a button programmatically in C# window app?
问题 I know that it easy to just drag and drop a button, however a lecturer insists on creating buttons programmatically. In the Form1_Load method what code should I write to create a simple button? private void Form1_Load(object sender, System.EventArgs e) { } So that on Load the button would show? 回答1: As you said it is Winforms, you can do the following... First create a new Button object. Button newButton = new Button(); Then add it to the form inside that function using: this.Controls.Add