ویژوال 30 شارپ

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

ویژوال 30 شارپ

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

Form Shadow

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

    private const int CS_DROPSHADOW = 0x00020000;

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams p = base.CreateParams;
            p.ClassStyle |= CS_DROPSHADOW;
            return p;
        }
    }
}

Form Opacity

private void button1_Click(object sender, EventArgs e)
{
    this.Opacity = 1;
    for (int i = 0; i < 100; i++)
    {
        this.Opacity -= 0.01;
        Application.DoEvents();
    }
}

Follower

bool b = false;
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            b = true;
            a.Clear();
        }

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

        }
        ArrayList a = new ArrayList();
        Point[] p = new Point[50];
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (b == true)
            {
                a.Add(new Point(e.X, e.Y));
                if (a.Count >= 50)
                {
                    for (int i = 0; i < a.Count - 50; i++)
                    {
                        a.RemoveAt(i);
                    }

                    a.CopyTo(p);
                }
                else
                {
                    a.CopyTo(p);
                }
                Bitmap bp = new Bitmap(this.Width, this.Height);
                Graphics g = Graphics.FromImage(bp);
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                Pen pn = new Pen(Brushes.Black);
                pn.Width = 2;
                pn.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                g.DrawLines(pn, p);
                this.BackgroundImage = bp;
            }

Filled Squere

private void Form1_Paint(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);
    // Create points that define polygon.
    Point point1 = new Point(30, 50);
    Point point2 = new Point(100, 25);
    Point point3 = new Point(200, 5);
    Point point4 = new Point(250, 50);
    Point point5 = new Point(270, 100);
    Point point6 = new Point(250, 250);
    Point[] curvePoints = {point1, point2, point3, point4, point5, point6};
    // Draw polygon to screen.
    g.DrawPolygon(blackPen, curvePoints);
    // Fill polygon
    g.FillPolygon(Brushes.Red, curvePoints);
}

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