How to draw and fill ellipse with random colors in Windows Forms (WinForms) C#

1 Answer

0 votes
using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Random rnd = new Random();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            Color c = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255));

            SolidBrush brush = new SolidBrush(c);

            Graphics graphics;

            graphics = this.CreateGraphics();

            graphics.FillEllipse(brush, new Rectangle(50, 50, 200, 300));

            brush.Color = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255));
            graphics.FillEllipse(brush, new Rectangle(70, 70, 300, 200));

            brush.Dispose();
            graphics.Dispose();
        }
    }
}


answered Nov 3, 2014 by avibootz
edited Jun 24, 2017 by avibootz
...