hi all
i'm trying to draw an oval/ellipse over an existing square
the problem is that the oval is drawn behind the rectangle
how do i fix this?
here is my form's code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Quoridor
{

    public partial class Game : Form
    {
        public const int N = 7;
        
        GameNode[,] Mat = new GameNode[7,7];
        public Game()
        {
            InitializeComponent();
           for(int i=0;i<N;i++)
               for(int j=0;j<N;j++)
               {
                     Mat[i, j] = new GameNode();
                     Mat[i, j].pictureBox = new PictureBox();
                  //   Mat[i, j].pictureBox.BorderStyle = BorderStyle.Fixed3D; 
                     Mat[i, j].pictureBox.Location = new Point(10+i*50+i*10, 10+j*50+j*10);
                     Mat[i, j].pictureBox.BackColor = System.Drawing.Color.Salmon;
                     Mat[i, j].pictureBox.Size = new System.Drawing.Size(50, 50) ;
                     Mat[i, j].name = i.ToString() + j.ToString();
                     this.Controls.Add(Mat[i, j].pictureBox);
                 }
             for(int i=0;i<N;i++)
                 for (int j = 0; j < N; j++)
                 {
                     if (i == 0)
                     {
                         if (j == 0)
                         {
                             Mat[i, j].rn = Mat[i, j + 1];
                             Mat[i, j].dn = Mat[i + 1, j];
                         }
                         else
                             if (j == 6)
                             {
                                 Mat[i, j].ln = Mat[i, j - 1];
                                 Mat[i, j].dn = Mat[i + 1, j];
                             }
                             else
                             {
                                 Mat[i, j].rn = Mat[i, j + 1];
                                 Mat[i, j].ln = Mat[i, j - 1];
                                 Mat[i, j].dn = Mat[i + 1, j];
                             }
                     }


                     else
                         if (i == 6)
                         {
                             if (j == 0)
                             {
                                 Mat[i, j].rn = Mat[i, j + 1];
                                 Mat[i, j].un = Mat[i - 1, j];
                             }
                             else
                                 if (j == 6)
                                 {
                                     Mat[i, j].ln = Mat[i, j - 1];
                                     Mat[i, j].un = Mat[i - 1, j];
                                 }
                                 else
                                 {
                                     Mat[i, j].rn = Mat[i, j + 1];
                                     Mat[i, j].ln = Mat[i, j - 1];
                                     Mat[i, j].un = Mat[i - 1, j];
                                 }
                         }
                 
                         else
                             if ((j == 0) &&(i!=0) &&(i!=6)) {
                                 
                                     
                                         Mat[i, j].rn = Mat[i, j + 1];
                                       //  Mat[i, j].ln = Mat[i, j - 1];
                                         Mat[i, j].dn = Mat[i + 1, j];
                                     
                             
                             }
                 
                            else
                                 if (j == 6)
                                 {
                                    // Mat[i, j].rn = Mat[i, j + 1];
                                     Mat[i, j].ln = Mat[i, j - 1];
                                     Mat[i, j].un = Mat[i - 1, j];
                                 }

                                 else
                                 {
                                     Mat[i, j].rn = Mat[i, j + 1];
                                     Mat[i, j].ln = Mat[i, j - 1];
                                     Mat[i, j].un = Mat[i - 1, j];
                                     Mat[i, j].dn = Mat[i + 1, j];
                                 
                                 }                            
          
        }

        private void Game_Load(object sender, EventArgs e)
        {
            
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click_1(object sender, EventArgs e)
        {

        }

        private void Game_MouseHover(object sender, EventArgs e)
        {

        }

        private void Game_MouseMove(object sender, MouseEventArgs e)
        {
            //label1.Text = e.X.ToString;
        }

        private void Game_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
          
            System.Drawing.Graphics formGraphics = this.CreateGraphics();
            formGraphics.FillEllipse(myBrush, new Rectangle(0, 0, 200, 300));
           
        }
    }
}

Edited 6 Years Ago by severman: n/a

when you draw using the form's on paint method you are drawing directly to the form. any controls you create and add to the form are on top of the form. so if you draw on the form, the controls will ALWAYS be on top of your drawings.

you can't just draw a circle on top of multiple controls. If you need complicated drawing consider not using controls, but instead using rectangles and manually drawing all the needed elements of the composite.

when you draw using the form's on paint method you are drawing directly to the form. any controls you create and add to the form are on top of the form. so if you draw on the form, the controls will ALWAYS be on top of your drawings.

you can't just draw a circle on top of multiple controls. If you need complicated drawing consider not using controls, but instead using rectangles and manually drawing all the needed elements of the composite.

can u explain me how to i draw an oval with a rectangle like u said?

May I point out also that on line 139 you used CreateGraphics.
This is not needed you get one Graphics object for free from the PaintEventArgs argument of the Paint handler.
Graphics formGraphics = e.Graphics;

May I point out also that on line 139 you used CreateGraphics.
This is not needed you get one Graphics object for free from the PaintEventArgs argument of the Paint handler.
Graphics formGraphics = e.Graphics;

10x for the help!

This question has already been answered. Start a new discussion instead.