You can create your GUI 'by hand' if you so desire. Open one of your GUI projects and take a look at the Form1.Designer.cs file (for example). That's the stuff you'll have to do to create a form and add controls to it. The Program.cs shows how you'd start up the form you've created.
It's just easier to do in the GUI than it is by hand.
Momerath
Senior Poster
3,734 posts since Aug 2010
Reputation Points: 1,336
Solved Threads: 624
Skill Endorsements: 13
Start a new windows forms app.
Open the Form.cs file and add the extra code after the //+++
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//+++
private System.Windows.Forms.Button MyBtn;
public Form1()
{
InitializeComponent();
//+++
this.MyBtn = new System.Windows.Forms.Button();
this.MyBtn.Location = new System.Drawing.Point(100, 100);
this.MyBtn.Name = "MyBtn";
this.MyBtn.Size = new System.Drawing.Size(75, 23);
this.MyBtn.TabIndex = 2;
this.MyBtn.Text = "A button";
this.MyBtn.UseVisualStyleBackColor = true;
this.MyBtn.Click += new System.EventHandler(this.MyBtn_Click);
this.Controls.Add(MyBtn);
}
//+++
private void MyBtn_Click(object sender, EventArgs e)
{
MessageBox.Show("My button clicked.");
}
}
}
Run and try it out, this is a Button created without using the VS Designer.
As Momerath I prefer the Designer, who does al that coding for me.
It is still important to know what is happening under the hood and if I have a situation where I want 100 buttons I still program this way, putting al this code in a loop to generate my 100 buttons. In such a situation it becomes harder to use the designer and coding is far better.
You can also use pure C# code with WPF, but I think few people do that.
ddanbe
Industrious Poster
4,375 posts since Oct 2008
Reputation Points: 2,126
Solved Threads: 738
Skill Endorsements: 26
Question Answered as of 1 Year Ago by
ddanbe
and
Momerath