Im hoping more people will use codedom since it is alot easier, and way more efficient
I will not be telling why it wont compile or anything of the sort, I will just be teaching you how to get your code ready for CodeDom.
For this tutorial im going to use a fake Microsoft Point "gen" that I put together in less than 3 minutes.
Double click on your main form, and then open notepad.
At the top of your using's you should see this, unless you have added more :
As you can see, I have System.Linq; Highlighted, just delete it. It isn't needed, It has caused error's with my other projects so I just continued to remove it.
Now in your code copy everything from and including the usings to the last closing bracket.
In my case it would look something like this :
and paste it into notepad, then add these following usings to the top, with the rest, and remove any duplicates .Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace MsPgen { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { textBox1.Text = "DQYHK - 2T8TG - MRXCF - RJGDC - XBX6J"; MessageBox.Show("Thanks for using the gen, it'll take 24 hours to get a new code."); } } }
Yours hopefully will look differentCode:using System.IO; using System.Threading; using System.Net; using System.Reflection; using System.Runtime.InteropServices; using System; using System.Windows.Forms; using Microsoft.VisualBasic; using System.Diagnostics;
First click the expand button as shown in the picture, next to your form.
Then right click on Your-form-name Designer and view code, as shown in the picture above.
Your going to want to place this line of code :Right afterCode:private System.ComponentModel.IContainer components = null;It declares the container, which the components of the form use.Code:public partial class Form1 : Form {
Back in the IDE, click on the little expanding box that says "Wndows form designer generated code"
And copy everything from where the region starts, to where it ends, and the control declarations at the end, like so :
And back to notepad, scroll down to the last two closing brackets, and before them both, paste that code.Code:#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.button1 = new System.Windows.Forms.Button(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(2, 97); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(281, 21); this.button1.TabIndex = 0; this.button1.Text = "Generate"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(2, 74); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(71, 17); this.checkBox1.TabIndex = 1; this.checkBox1.Text = "12 Month"; this.checkBox1.UseVisualStyleBackColor = true; // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Location = new System.Drawing.Point(182, 74); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(101, 17); this.checkBox2.TabIndex = 2; this.checkBox2.Text = "4000 MS Points"; this.checkBox2.UseVisualStyleBackColor = true; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(12, 22); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(260, 20); this.textBox1.TabIndex = 3; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 121); this.Controls.Add(this.textBox1); this.Controls.Add(this.checkBox2); this.Controls.Add(this.checkBox1); this.Controls.Add(this.button1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Form1"; this.Text = "Bmans Genny."; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.CheckBox checkBox2; private System.Windows.Forms.TextBox textBox1;
Now it should look something like this, and the usings you declared earlier :
Well thats all, I hope you enjoyedCode:namespace MsPgen { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { textBox1.Text = "DQYHK - 2T8TG - MRXCF - RJGDC - XBX6J"; MessageBox.Show("Thanks for using the gen, it'll take 24 hours to get a new code."); } #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.button1 = new System.Windows.Forms.Button(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(2, 97); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(281, 21); this.button1.TabIndex = 0; this.button1.Text = "Generate"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(2, 74); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(71, 17); this.checkBox1.TabIndex = 1; this.checkBox1.Text = "12 Month"; this.checkBox1.UseVisualStyleBackColor = true; // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Location = new System.Drawing.Point(182, 74); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(101, 17); this.checkBox2.TabIndex = 2; this.checkBox2.Text = "4000 MS Points"; this.checkBox2.UseVisualStyleBackColor = true; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(12, 22); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(260, 20); this.textBox1.TabIndex = 3; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 121); this.Controls.Add(this.textBox1); this.Controls.Add(this.checkBox2); this.Controls.Add(this.checkBox1); this.Controls.Add(this.button1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Form1"; this.Text = "Bmans Genny."; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.CheckBox checkBox2; private System.Windows.Forms.TextBox textBox1; } }
Results 1 to 1 of 1
- 04 Sep. 2010 09:32am #1
[Tut] Making your C# Code, codedom ready.
Shh, I'm watching My little pony.