Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

C# BEGGINNER NEEDS HELP

hassaancshassaancs Posts: 2Member
I AM A C# BEGINNER WITH A LITTLE BACK GROUND IN C.
I NEED HELP OF A PERSON WHO CAN MAIL ME SOME CODES BY WHICH ICAN LEARN DEVELOPING C# PROGRAMMING
THANKS

Comments

  • IDKIDK Posts: 1,784Member
    : I AM A C# BEGINNER WITH A LITTLE BACK GROUND IN C.
    : I NEED HELP OF A PERSON WHO CAN MAIL ME SOME CODES BY WHICH ICAN LEARN DEVELOPING C# PROGRAMMING
    : THANKS
    :
    :
    If you got the Visual C# it's
    easy. Just try to play around
    and it will be easy and fun.

    Here's Life. A program that
    shows that complex structures
    can be found in small enviroments.
    [code]
    #region Using directives

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    #endregion

    namespace Life
    {
    partial class Form1 : Form
    {
    int zoom = 5,
    w = 10,
    h = 10;
    bool mouselive = false,
    mousedown = false;
    Life life = new Life(100, 100);

    public Form1()
    {
    InitializeComponent();
    lifepaint();
    //pB.Height = h * zoom;
    //pB.Width = w * zoom;
    }
    //paint
    private void pB_Paint(object sender, PaintEventArgs e)
    {
    lifepaint();
    }
    private void lifepaint()
    {
    Pen black = new Pen(Color.Black);
    SolidBrush white = new SolidBrush(Color.White);
    SolidBrush blue = new SolidBrush(Color.Blue);
    Graphics g = pB.CreateGraphics();
    for (int x = 0; x < pB.Width; x += zoom)
    {
    g.DrawLine(black, x, 0, x, pB.Height);
    }
    for (int y = 0; y < pB.Height; y += zoom)
    {
    g.DrawLine(black, 0, y, pB.Width, y);
    }
    for (int x = 0; x < pB.Width; x += zoom)
    {
    for (int y = 0; y < pB.Height; y += zoom)
    {
    if (life.matrix[x / zoom, y / zoom])
    g.FillRectangle(blue, x + 1, y + 1, zoom - 1, zoom - 1);
    else
    g.FillRectangle(white, x + 1, y + 1, zoom - 1, zoom - 1);
    }
    }
    }
    //mouse
    private void pB_MouseDown(object sender, MouseEventArgs e)
    {
    mousedown = true;
    int x =e.X / zoom,
    y =e.Y / zoom;
    if (life.matrix[x, y])
    mouselive = false;
    else
    mouselive = true;
    life.matrix[x, y] = mouselive;
    lifepaint();
    Update();
    }
    private void pB_MouseMove(object sender, MouseEventArgs e)
    {
    if (mousedown)
    {
    int x = e.X / zoom,
    y = e.Y / zoom;
    life.matrix[x, y] = mouselive;
    lifepaint();
    Update();
    }
    }
    private void pB_MouseUp(object sender, MouseEventArgs e)
    {
    mousedown = false;
    }

    private void Go_Click(object sender, EventArgs e)
    {
    stepTimer.Enabled = true;
    }
    private void Stop_Click(object sender, EventArgs e)
    {
    stepTimer.Enabled = false;
    }
    private void Clear_Click(object sender, EventArgs e)
    {
    life = new Life(100, 100);
    stepTimer.Enabled = false;
    lifepaint();
    }
    private void stepTimer_Tick(object sender, EventArgs e)
    {
    for (int i = 0; i < Properties.Settings.Value.Skip; i++)
    life = life.step();
    lifepaint();
    }

    private void Options_Click(object sender, EventArgs e)
    {
    Form2 F2 = new Form2();
    F2.ShowDialog(this);
    int fps = Properties.Settings.Value.FPS;
    stepTimer.Interval = 1000 / fps;
    }
    }
    class Life
    {
    public bool[,] matrix;
    int height,
    width;
    public Life(int Height, int Width)
    {
    height = Height;
    width = Width;
    matrix = new bool[height, width];
    }
    public Life step()
    {
    Life rlife = new Life(height,width);
    for (int x = 1;x<height-1;x++)
    for (int y = 1; y < width - 1; y++)
    {
    //calc neighbors
    int numNe = 0;
    {
    if (matrix[x - 1, y - 1])
    numNe++;
    if (matrix[x - 1, y])
    numNe++;
    if (matrix[x - 1, y + 1])
    numNe++;
    if (matrix[x, y - 1])
    numNe++;
    if (matrix[x, y + 1])
    numNe++;
    if (matrix[x + 1, y - 1])
    numNe++;
    if (matrix[x + 1, y])
    numNe++;
    if (matrix[x + 1, y + 1])
    numNe++;
    }
    if (numNe == 3)
    rlife.matrix[x, y] = true;
    else if (numNe == 2 && matrix[x, y])
    rlife.matrix[x, y] = true;
    else
    rlife.matrix[x, y] = false;
    }
    return rlife;
    }
    }
    }
    [/code]

    The PROgrammer Niklas Ulvinge

  • IDKIDK Posts: 1,784Member
    Oh I forgot...
    This one am I
    really proud of.

    It uses a lot of
    new C# func's.

    If you use Complex
    Numbers this is
    what you want to
    have.

    [code]
    #region Using directives

    using System;

    #endregion

    namespace Ulvinge
    {
    public struct ComplexNumber
    {
    //real
    public double r;
    public double i;
    //imaginary variables
    public double argument
    {
    get
    {
    //return Math.Atan(i / r); wrong!
    return Math.Atan2(i, r);
    }
    set
    {
    r = modulus * Math.Cos(value);
    i = modulus * Math.Sin(value);
    }
    }
    public double modulus
    {
    get
    {
    return Math.Sqrt(r * r + i * i);
    }
    set
    {
    r = value * Math.Cos(argument);
    i = value * Math.Sin(argument);
    }
    }
    //init
    public ComplexNumber(double real, double imaginary)
    {
    r = real;
    i = imaginary;
    }
    //explicit
    public static explicit operator ComplexNumber(double r)
    {
    return new ComplexNumber(r, 0);
    }
    //ToString
    public override string ToString()//(R+Ii
    {
    return "(" + r + " + " + i + " i)";
    }
    public string ToStringRound() //(R+Ii) aproximate value
    {
    return "(" + ((double)((int)(r * 1000)) / 1000).ToString()
    + " + " + ((double)((int)(i * 1000)) / 1000).ToString()
    + "i)";
    }
    public string ToStringPolar() //r(cos(q)+isin(q)).
    {
    return this.modulus.ToString() +
    "(cos(" + this.argument.ToString() +
    ")+isin(" + this.argument.ToString() + "))";
    }
    //math
    public double Norm()
    {
    return (r * r + i * i);
    }
    public ComplexNumber Conj()
    {
    return new ComplexNumber(r, -i);
    }
    public ComplexNumber Pow(double n)
    {
    double ra = Math.Pow(modulus, n),
    th = argument * n;
    return new ComplexNumber(ra * Math.Cos(th),
    ra * Math.Sin(th));
    }
    public ComplexNumber Pow(ComplexNumber n)
    {//(a+ib)^(c+di) = e^[(c+id)*ln(a+ib)] = (a+b)c/2e-d*arg(a+ib){cos[c*arg(a+ib)+d*ln(a+b)]+isin[c*arg(a+ib)+d*ln(a+b)]}
    ComplexNumber a = new ComplexNumber(Math.Cos(n.r * this.argument + (n.i / 2) * Math.Log(this.r * this.r + this.i * this.i)),
    Math.Sin(n.r * this.argument + (n.i / 2) * Math.Log(this.r * this.r + this.i * this.i)));
    return Math.Pow(this.r * this.r + this.i * this.i, n.r / 2) * Math.Exp(n.i * this.argument) * (a);
    }
    #region binary operators
    //plus
    public static ComplexNumber operator +(
    ComplexNumber a, ComplexNumber b)
    {
    return new ComplexNumber(a.r + b.r,
    a.i + b.i);
    }
    public static ComplexNumber operator +(
    ComplexNumber a, double b)
    {
    return new ComplexNumber(a.r + b,
    a.i);
    }
    public static ComplexNumber operator +(
    double a, ComplexNumber b)
    {
    return new ComplexNumber(b.r + a,
    b.i);
    }
    //minus
    public static ComplexNumber operator -(
    ComplexNumber a, ComplexNumber b)
    {
    return new ComplexNumber(a.r - b.r,
    a.i - b.i);
    }
    public static ComplexNumber operator -(
    ComplexNumber a, double b)
    {
    return new ComplexNumber(a.r - b,
    a.i);
    }
    public static ComplexNumber operator -(
    double a, ComplexNumber b)
    {
    return new ComplexNumber(b.r - a,
    b.i);
    }
    //multiplication
    public static ComplexNumber operator *(
    ComplexNumber a, ComplexNumber b)
    {
    double r = a.r * b.r - a.i * b.i;
    double i = a.r * b.i + a.i * b.r;
    return new ComplexNumber(r, i);
    }
    public static ComplexNumber operator *(
    ComplexNumber a, double b)
    {
    double r = a.r * b - a.i;
    double i = a.r * b + a.i;
    return new ComplexNumber(r, i);
    }
    public static ComplexNumber operator *(
    double a, ComplexNumber b)
    {
    double r = b.r * a - b.i;
    double i = b.r * a + b.i;
    return new ComplexNumber(r, i);
    }
    //division
    public static ComplexNumber operator /(
    ComplexNumber a, ComplexNumber b)
    {
    double r = a.r * b.r + a.i * b.i;
    double i = a.i * b.r - a.r * b.i;
    double d = b.r * b.r + b.i * b.i;
    return new ComplexNumber(r / d, i / d);
    }
    public static ComplexNumber operator /(
    ComplexNumber a, double d)
    {
    return new ComplexNumber(a.r / d, a.i / d);
    }
    public static ComplexNumber operator /(
    double a, ComplexNumber b)
    {
    double r = a * b.r;
    double i = a * b.i;
    double d = b.r * b.r + b.i * b.i;
    return new ComplexNumber(r / d, i / d);
    }
    //modulus
    public static ComplexNumber operator %(
    ComplexNumber a, ComplexNumber b)
    {
    double r = a.r * b.r + a.i * b.i;
    double i = a.i * b.r - a.r * b.i;
    double d = b.r * b.r + b.i * b.i;
    return new ComplexNumber(r % d, i % d);
    }
    public static ComplexNumber operator %(
    ComplexNumber a, double d)
    {
    return new ComplexNumber(a.r % d, a.i % d);
    }
    public static ComplexNumber operator %(
    double a, ComplexNumber b)
    {
    double r = a * b.r;
    double i = a * b.i;
    double d = b.r * b.r + b.i * b.i;
    return new ComplexNumber(r % d, i % d);
    }
    //comparision
    public static bool operator >(
    ComplexNumber a,ComplexNumber b)
    {
    return a.argument > b.argument;
    }
    public static bool operator >=(
    ComplexNumber a, ComplexNumber b)
    {
    return a.argument >= b.argument;
    }
    public static bool operator <(
    ComplexNumber a, ComplexNumber b)
    {
    return a.argument < b.argument;
    }
    public static bool operator <=(
    ComplexNumber a, ComplexNumber b)
    {
    return a.argument <= b.argument;
    }
    #endregion
    #region unary operators
    //increment
    public static ComplexNumber operator ++(
    ComplexNumber a)
    {
    a.r++;
    return a;
    }
    public static ComplexNumber operator --(
    ComplexNumber a)
    {
    a.r--;
    return a;
    }
    //fast way of conjunction
    public static ComplexNumber operator !(
    ComplexNumber a)
    {
    return a.Conj();
    }
    //geting it right
    public static ComplexNumber operator +(
    ComplexNumber a)
    {
    a.r = +a.r;
    return a;
    }
    public static ComplexNumber operator -(
    ComplexNumber a)
    {
    a.r = -a.r;
    return a;
    }
    #endregion
    }
    }
    [/code]

    The PROgrammer Niklas Ulvinge

  • hassaancshassaancs Posts: 2Member
    DEAR BROTHER
    THANKS ALOT
    HOPEFULLY U WILL SEND ME MORE CODES.

    : : I AM A C# BEGINNER WITH A LITTLE BACK GROUND IN C.
    : : I NEED HELP OF A PERSON WHO CAN MAIL ME SOME CODES BY WHICH ICAN LEARN DEVELOPING C# PROGRAMMING
    : : THANKS
    : :
    : :
    : If you got the Visual C# it's
    : easy. Just try to play around
    : and it will be easy and fun.
    :
    : Here's Life. A program that
    : shows that complex structures
    : can be found in small enviroments.
    : [code]
    : #region Using directives
    :
    : using System;
    : using System.Collections.Generic;
    : using System.ComponentModel;
    : using System.Data;
    : using System.Drawing;
    : using System.Windows.Forms;
    :
    : #endregion
    :
    : namespace Life
    : {
    : partial class Form1 : Form
    : {
    : int zoom = 5,
    : w = 10,
    : h = 10;
    : bool mouselive = false,
    : mousedown = false;
    : Life life = new Life(100, 100);
    :
    : public Form1()
    : {
    : InitializeComponent();
    : lifepaint();
    : //pB.Height = h * zoom;
    : //pB.Width = w * zoom;
    : }
    : //paint
    : private void pB_Paint(object sender, PaintEventArgs e)
    : {
    : lifepaint();
    : }
    : private void lifepaint()
    : {
    : Pen black = new Pen(Color.Black);
    : SolidBrush white = new SolidBrush(Color.White);
    : SolidBrush blue = new SolidBrush(Color.Blue);
    : Graphics g = pB.CreateGraphics();
    : for (int x = 0; x < pB.Width; x += zoom)
    : {
    : g.DrawLine(black, x, 0, x, pB.Height);
    : }
    : for (int y = 0; y < pB.Height; y += zoom)
    : {
    : g.DrawLine(black, 0, y, pB.Width, y);
    : }
    : for (int x = 0; x < pB.Width; x += zoom)
    : {
    : for (int y = 0; y < pB.Height; y += zoom)
    : {
    : if (life.matrix[x / zoom, y / zoom])
    : g.FillRectangle(blue, x + 1, y + 1, zoom - 1, zoom - 1);
    : else
    : g.FillRectangle(white, x + 1, y + 1, zoom - 1, zoom - 1);
    : }
    : }
    : }
    : //mouse
    : private void pB_MouseDown(object sender, MouseEventArgs e)
    : {
    : mousedown = true;
    : int x =e.X / zoom,
    : y =e.Y / zoom;
    : if (life.matrix[x, y])
    : mouselive = false;
    : else
    : mouselive = true;
    : life.matrix[x, y] = mouselive;
    : lifepaint();
    : Update();
    : }
    : private void pB_MouseMove(object sender, MouseEventArgs e)
    : {
    : if (mousedown)
    : {
    : int x = e.X / zoom,
    : y = e.Y / zoom;
    : life.matrix[x, y] = mouselive;
    : lifepaint();
    : Update();
    : }
    : }
    : private void pB_MouseUp(object sender, MouseEventArgs e)
    : {
    : mousedown = false;
    : }
    :
    : private void Go_Click(object sender, EventArgs e)
    : {
    : stepTimer.Enabled = true;
    : }
    : private void Stop_Click(object sender, EventArgs e)
    : {
    : stepTimer.Enabled = false;
    : }
    : private void Clear_Click(object sender, EventArgs e)
    : {
    : life = new Life(100, 100);
    : stepTimer.Enabled = false;
    : lifepaint();
    : }
    : private void stepTimer_Tick(object sender, EventArgs e)
    : {
    : for (int i = 0; i < Properties.Settings.Value.Skip; i++)
    : life = life.step();
    : lifepaint();
    : }
    :
    : private void Options_Click(object sender, EventArgs e)
    : {
    : Form2 F2 = new Form2();
    : F2.ShowDialog(this);
    : int fps = Properties.Settings.Value.FPS;
    : stepTimer.Interval = 1000 / fps;
    : }
    : }
    : class Life
    : {
    : public bool[,] matrix;
    : int height,
    : width;
    : public Life(int Height, int Width)
    : {
    : height = Height;
    : width = Width;
    : matrix = new bool[height, width];
    : }
    : public Life step()
    : {
    : Life rlife = new Life(height,width);
    : for (int x = 1;x<height-1;x++)
    : for (int y = 1; y < width - 1; y++)
    : {
    : //calc neighbors
    : int numNe = 0;
    : {
    : if (matrix[x - 1, y - 1])
    : numNe++;
    : if (matrix[x - 1, y])
    : numNe++;
    : if (matrix[x - 1, y + 1])
    : numNe++;
    : if (matrix[x, y - 1])
    : numNe++;
    : if (matrix[x, y + 1])
    : numNe++;
    : if (matrix[x + 1, y - 1])
    : numNe++;
    : if (matrix[x + 1, y])
    : numNe++;
    : if (matrix[x + 1, y + 1])
    : numNe++;
    : }
    : if (numNe == 3)
    : rlife.matrix[x, y] = true;
    : else if (numNe == 2 && matrix[x, y])
    : rlife.matrix[x, y] = true;
    : else
    : rlife.matrix[x, y] = false;
    : }
    : return rlife;
    : }
    : }
    : }
    : [/code]
    :
    : The PROgrammer Niklas Ulvinge
    :
    :

Sign In or Register to comment.