Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[C#][Tut] How to make your code, CodeDom ready.

Im hoping more people will use codedom since it is alot easier, and way more efficient :D

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 :
[IMG]http://i822.photobucket.com/albums/zz144/Asydix/2.jpg[/IMG]

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 :
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.");

        }
    }
}

and paste it into notepad, then add these following usings to the top, with the rest, and remove any duplicates .

Code
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;

Yours hopefully will look different :)

[IMG]http://i822.photobucket.com/albums/zz144/Asydix/3.jpg[/IMG]

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 :
Code
private System.ComponentModel.IContainer components = null;
Right after
Code
public partial class Form1 : Form
    {

It declares the container, which the components of the form use.

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 :
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;

And back to notepad, scroll down to the last two closing brackets, and before them both, paste that code.

Now it should look something like this, and the usings you declared earlier :

Code
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;    

    }
}

Well thats all, hope I helped.
Thanks for this! Itl probably be similar for vb, and will come in handy :)
Thanks been looking for something like this for a little bit now


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by The Masked PearJan 26, 2022 12:18 PM 11 312 Jan 26, 2022 12:18 PM
Last Post: mose3c
[.NET] by markzuckerbergJul 15, 2018 08:07 AM 13 663 Jul 15, 2018 08:07 AM
Last Post: gigajew
[C#] by WubixMar 24, 2018 06:47 PM 5 242 Mar 24, 2018 06:47 PM
Last Post: Wubix