ویژوال 30 شارپ

سورس کدهای جالب سی شارپ فقط با یک نگاه

ویژوال 30 شارپ

سورس کدهای جالب سی شارپ فقط با یک نگاه

Encrypt String

using System.Security.Cryptography;

private string encryptString(string strToEncrypt)
{
    UTF8Encoding ue = new UTF8Encoding();
    byte[] bytes = ue.GetBytes(strToEncrypt);

    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    byte[] hashBytes = md5.ComputeHash(bytes);

    // Bytes to string
    return System.Text.RegularExpressions.Regex.Replace
        (BitConverter.ToString(hashBytes), "-", "").ToLower();
}

MessageBox.Show(encryptString("Sinpin"));

Drawing Line

int x1, y1 = 0;
        bool c = false;
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
                x1 = e.X;
                y1 = e.Y;
                c = true;
                al.Add(new Point(e.X, e.Y));
        }
        System.Collections.ArrayList al = new System.Collections.ArrayList();
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (c == true)
            {
                System.Drawing.Drawing2D.LinearGradientBrush brush1= new
                System.Drawing.Drawing2D.LinearGradientBrush(
                new Rectangle(0, 0, 2, 2), Color.YellowGreen, Color.Green,
                System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
                Bitmap b = new Bitmap(Width, Height);
                Graphics g = Graphics.FromImage(b);
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                al.Add(new Point(e.X, e.Y));
                Point[] p = new Point[al.Count];
                al.CopyTo(p);
                g.DrawLines(new Pen(brush1,5), p);
                this.BackgroundImage = b;
            }
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            c = false;
        }

Drawing Chart 2

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            int a, b, c, d = 0;
            a = int.Parse(numericUpDown1.Value.ToString());
            b = a * 3600;
            c = b / 1000;
            d = 50;
            System.Drawing.Drawing2D.LinearGradientBrush b1 = new System.Drawing.Drawing2D.LinearGradientBrush(new
     Rectangle(50, 20, 190, 170), Color.Yellow, Color.Green, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);

            SolidBrush sb = new SolidBrush(Color.Black);
            Bitmap bit = new Bitmap(Width, Height);
            Graphics g = Graphics.FromImage(bit);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.DrawPie(new Pen(sb, 1), d, 20, 190, 170, 0, 360);
            sb.Color = Color.Silver;
            g.FillPie(sb, d, 20, 190, 170, 0, 360);
            sb.Color = Color.Black;
            g.DrawPie(new Pen(sb, 1), d, 20, 190, 170, -c, c);
            sb.Color = Color.Yellow;
            g.FillPie(b1, d, 20, 190, 170, -c, c);
            this.BackgroundImage = bit;

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            numericUpDown1_ValueChanged(null, null);
        }

Denabled Close Button

using System.Runtime.InteropServices;

private const int SC_CLOSE = 0xF060;
private const int MF_GRAYED = 0x1;
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
private static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);

private void Form1_Load(object sender, System.EventArgs e)
{
    EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
}

Circle Form

private void Form1_Load(object sender, EventArgs e)
{
    this.Height = 350;
    this.Width = 350;
    //Creating circle path
    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
    path.AddEllipse(0, 0, 300, 300);
    //Creating the region from the circle path
    this.Region = new Region(path);
    this.Show();
}