Brushes, Graphics and Ellipses


This code creates solid filled ellipses. MSDN Reference



Add a panel from the toolbox and call it "panDraw". Add a button.

    pic
  
        private void btnDraw_Click(object sender, EventArgs e)
        {
            // create a Graphics object reference, gr, for the Panel control, panDraw.
            // this object is instantiated from the Graphics class.
            Graphics gr = panDraw.CreateGraphics();          
            
            
            // create a brush and give it a color
            Brush brR = new SolidBrush(Color.Red);  
            
            
            // Using the brush (brR), draw a rectangle 100px wide and 50px high at location x=10, y = 20
            gr.FillEllipse(brR, 10, 20,100, 50);

            
            // Create a new brush and give it a color
            Brush brb = new SolidBrush(Color.Blue);  
            
            
            // Using the new brush (brB), draw a rectangle 100px wide and 50px high at location x=120, y = 130
            gr.FillElllipse(brB, 120, 130, 100, 50); // x,y,w,h
        }


Add a panel from the toolbox and call it "panDraw". Add a button. Loop and draw

    pic
  
        private void btnDraw_Click(object sender, EventArgs e)
        {
            // for location
            int x = 0, y = 0, looper = 0;

            
            // create a Graphics object, gr, from the Graphics class and places it on the panel
            Graphics gr = panDraw.CreateGraphics();         
     
     
            // create brushes
            Brush brR = new SolidBrush(Color.FromArgb(100, 250, 100, 50)); // all values 0-255
            Brush brB = new SolidBrush(Color.FromArgb(100, 70, 100, 250)); // all values 0-255
            Brush brG = new SolidBrush(Color.FromArgb(150, 70, 230, 150)); // all values 0-255
     
     
            // Using the brush indicated, loop and draw at x,y with dimension  w,h
            while (looper < 5)
            {
                gr.FillEllipse(brR, x, y, 190, 150);
                x += 25;
                y += 40;
                gr.FillEllipse(brB, x, y, 160, 90);
                x += 40;
                y += 30;
                gr.FillEllipse(brG, x, y, 190, 190);
                looper++;
            }
        }