ویژوال 30 شارپ

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

ویژوال 30 شارپ

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

Random Text 2

private string GenerateId2()
{
    long i = 1;
    foreach (byte b in Guid.NewGuid().ToByteArray())
    {
        i *= ((int)b + 1);
    }
    return string.Format("{0:x}", i - DateTime.Now.Ticks);
}

Random Text

private string GenerateId1()
{
    return Guid.NewGuid().ToString();
}

Radar

using System.Drawing.Drawing2D;

int i = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            i += 2;
            Rectangle r = new Rectangle(0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1);
            Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(b);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            SolidBrush sb = new SolidBrush(Color.Blue);
            for (int k = 1; k < 180; k++)
            {
                sb.Color = Color.FromArgb((255 * k) / 180, 0, (255 * k) / 180, (255 * k) / 180);
                g.FillPie(sb, r, i + k, 1);
            }
            sb.Color = Color.FromArgb(0, 150, 150);
            g.FillEllipse(sb, new Rectangle(r.Width / 2 - 4, r.Height / 2 - 4, 8, 8));
            g.DrawEllipse(new Pen(Brushes.Blue), r);
            g.DrawEllipse(new Pen(sb), r);
            pictureBox1.Image = b;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.None;
            timer1.Interval = 1;
            this.Size = new Size(125, 125);
            pictureBox1.Size = new Size(125, 125);
            pictureBox1.BackColor = Color.FromArgb(64, 64, 64);
            this.TransparencyKey = pictureBox1.BackColor;
            Rectangle r = new Rectangle(0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1);
            SolidBrush lb = new SolidBrush(Color.Black);
            Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(b);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillEllipse(lb, r);
            pictureBox1.BackgroundImage = b;
        }

Program In Startup

private void AddStartUpKey(string _name, string  _path)
{
    RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
    key.SetValue(_name, _path);
}

private void RemoveStartUpKey(string _name)
{
    RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
    key.DeleteValue(_name, false);
}

Play Sound And Video

using System.Runtime.InteropServices;

string CommandString;
OpenFileDialog file = new OpenFileDialog();

[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);

private void button1_Click(object sender, System.EventArgs e)
{
    if (file.ShowDialog() == DialogResult.OK)
    {
        CommandString = "open " + "\"" + file.FileName + "\"" + " type MPEGVideo alias MediaFile";
        mciSendString(CommandString, null, 0, 0);
        CommandString = "play MediaFile";
        mciSendString(CommandString, null, 0, 0);
    }
}