Hello, I have some problems when getting the diagonal coordinates of the queen. What certain steps or algorithm could you suggest me as I am just manipulating the button list. It would be just fine for me if you suggest reworking the whole program for a better solution.

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 WindowsFormsApplication3
{
    public partial class eightqueens : Form
    {
        public eightqueens()
        {
            InitializeComponent();
        }

         List<Button> btnList = new List<Button>();
        private void eightqueens_Load(object sender, EventArgs e)
        {



            for(int x = 1, z = 1; x <= 8; x++)
            {

             for (int y = 1; y <= 8; y++, z++)
             {
                 Button btn = new Button();
                 btn.Size = new Size(30, 30);

                 flpBox.Controls.Add(btn);
                 btn.Name= (x).ToString(); // row
                 btn.Tag = (y).ToString(); // column assignment of number

                 if (y % 8 == 0)
                 {
                     flpBox.SetFlowBreak(btn, true);
                 }

                 btnList.Add(btn);
                 btn.Click += Button_Click;
             }
            }
        }

        private void flpBox_Paint(object sender, PaintEventArgs e)
        {

        }

        private void Button_Click(Object sender, EventArgs e)
        {
            Object btn = sender;

            if (((Button)btn).Text == "")
            {

                foreach (Button b in btnList)
                {
                    if (int.Parse(((Button)btn).Tag.ToString()) == int.Parse(b.Tag.ToString()))
                    {
                        b.Text = "x";
                    }

                    else if (int.Parse(((Button)btn).Name) == int.Parse(b.Name))
                    {
                        b.Text = "x";
                    }


                    else if (int.Parse(b.Name) == int.Parse(b.Tag.ToString()))
                    {

                    }

                }
                ((Button)btn).Text = "q";
            }

            else if (((Button)btn).Text == "q")
            {
                foreach (Button b in btnList)
                {
                    if (int.Parse(b.Name) == int.Parse(b.Tag.ToString()))
                    {
                        b.Text = "";
                    }
                }
                ((Button)btn).Text = "";

            }




        }
    }
}

Not entirely sure what you're after...

To find a diagonal, increase or decrease x and y by the same number...

Thanks for pointing that out. I will try to work it out!

How can I manipulate the buttons to print x diagonally upwards??? I could only make it work when the coordinates are equal to each other.

Sorry but I'm confused and don't know what you're trying to achieve. Could you give a more detailed explanation please?

Consider a carthesian coordinate system. By the way, invented by René Descartes in the 17th century, when in his bed and watching a fly walking on his ceiling!
Consider you are on the x-axis at coordinate x=0 and on the y-axis at coordinate y=0. It is called the origin.(x,y)=(0,0).
To go diagonally right and up you do (in a loop) (x++,y++) to go diagonally left and up you do (x--,y++) etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.