Sunday, 30 March 2014

ADD IMAGE FROM RESOURCES

Bitmap i = new Bitmap(projectname.properties.resources.filename);

RiGHT CLICK EVENT ON MOUSE BUTTON

if (e.Button == MouseButtons.Right)
                button1.Text = "Right Click";

OPERATOR OVERLOADING

class Complex
    {
        int real;
        int imag;
        public int Creal
        {
            get {return real;}
            set {real = value;}
        }
        public int Cimag
        {
            get { return imag; }
            set {imag = value;}
        }
        public Complex()
        {
            real = 0;
            imag = 0;
        }
        public Complex(int a, int b)
        {
            real = a;
            imag = b;
        }
        public override string ToString()
        {
            return real + "+" + imag + "i";
        }
        public static Complex operator +(Complex a, Complex b)
        {
            Complex temp = new Complex();
            temp.real = a.real + b.real;
            temp.imag = a.imag + b.imag;
            return temp;
        }

FREE HAND DRAWING

private void panel1_MouseUp(object sender, MouseEventArgs e)
{
a = 0;
}

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (a == 1)
{
Graphics g = panel1.CreateGraphics();
Pen p = new Pen(c, 25);
cloc = e.Location;
g.DrawLine(p, ploc, cloc);
ploc = e.Location;
}
}

private void panel1_MouseDown(object sender, MouseEventArgs e)
{
a = 1;
ploc = e.Location;

Random rn = new Random();
c = Color.FromArgb(rn.Next(0, 255), rn.Next(0, 255), rn.Next(0, 255));

}

DRAW RECTANGLE

if (isDrawing)
                {
                    Graphics g = panel1.CreateGraphics();
                    if (chk == 2)
                    {
                        Pen myPen = new Pen(currentColor, 2);
                        g.DrawRectangle(myPen, new Rectangle(lastLocation.X, lastLocation.Y, e.Location.X - lastLocation.X, e.Location.Y - lastLocation.Y));
                    }
                    else if (chk == 1)
                    {
                        HatchBrush hb;
                       // Random r = new Random();
                        hb = new HatchBrush(HatchStyle.Divot,currentColor);
                        g.FillRectangle(hb, new Rectangle(lastLocation.X, lastLocation.Y, e.Location.X - lastLocation.X, e.Location.Y - lastLocation.Y));
                        g.DrawString("Saira", new Font("Arial", 20), hb, new Point(e.Location.X, e.Location.Y));
                    }
                        g.Dispose();
                }

SHOW MESSAGE DIALOG AND LOAD FILE

// OpenImage.ShowDialog();
            OpenImage.Title = "Open Images";
            OpenImage.FileName = "";
           // OpenImage.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
OpenImage.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            OpenImage.Filter = "JPEG Images|*.jpg|Bitmap|*.bmp|GIF Files|*.gif";
            viewImagesToolStripMenuItem.Checked = !viewImagesToolStripMenuItem.Checked;
            if (viewImagesToolStripMenuItem.Checked && OpenImage.ShowDialog() == DialogResult.OK)
            {
                string name = OpenImage.FileName;
                pictureBox1.Image = Image.FromFile(name);
               
            }
            pictureBox1.Visible = !pictureBox1.Visible;