Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g  = pictureBox1.CreateGraphics();
            MyShape  ms = new MyShape(new RectangleF(10, 10, 30, 30), Color.Red);

            ms.Draw(g);
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Random r = new Random();

            Color[] colors = new Color[] { Color.Red, Color.Green, Color.Blue };

            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i < 5; ++i)
            {
                int     x  = r.Next(0, pictureBox1.Width);
                int     y  = r.Next(0, pictureBox1.Height);
                int     ci = r.Next(0, colors.Length);
                MyShape ms = new MyShape(new RectangleF(x, y, 30, 30), colors[ci]);
                ms.Draw(g);
            }
        }