Pages

Wednesday, 1 July 2015

C# Starting from Scratch

So many years ago, it seems I learnt how to program in C# a compiler developed by Microsoft. Well, recently I was asked if I could write some code to sort some data in a CSV format.

This is easy enough to do with Excel but with many data sets to be sorted in the future and with a bit of time till it will be used. I thought to myself what an opportunity to build a program using C#. Little did I know I have forgotten so much of what I have learnt I decided that I would pull out the old text book and start from the start. Or from where I think the start should be in this case.

Anyway here is the work that I have done today in the last half hour.


And here is the code that I used to implement it. Pretty straight forward code, give it a go, you forget how much fun mucking around with code it. 

Shout out too Douglas Bell & Mike Parr from C# for Students. Great book and will never throw this one out!

Hopefully I will keep you posted on how my little C# program for organising my CSV file goes.

namespace FirstDrawingProgram
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics paper;
            paper = pictureBox1.CreateGraphics();
            Bitmap pic = new Bitmap(@"C:\Users\Nathan\Pictures\Coding\Solved.bmp");
            Pen pen = new Pen(Color.Black);//Create a black pen

            paper.DrawRectangle(pen, 10, 10, 100, 50);
            paper.DrawRectangle(pen, 10, 75, 100, 100);
            paper.DrawEllipse(pen, 10, 75, 100, 100);
            paper.DrawImage(pic, 130, 10, 300, 300);
            paper.DrawEllipse(pen, 10, 10, 50, 50);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics paper;
            paper = pictureBox1.CreateGraphics();
            SolidBrush myBrush = new SolidBrush(Color.Black);
            paper.FillRectangle(myBrush, 10, 10, 90, 90);
        }

    }
}

No comments:

Post a Comment