Jump to content

Drawing Line over Form and labels

- - - - -

  • Please log in to reply
No replies to this topic

#1
Abbath1349

Abbath1349

    Newbie

  • Members
  • PipPip
  • 22 posts
I write ProgramTic Tac Toe. Can u tell me how i may draw line over form and labels?

public partial class Form1 : Form

    {

       

        Label[] X_0 = new Label[9];

        bool[] position = new bool[9];

       

        public Form1()

        {

            InitializeComponent();

            int x = 15, y = 15;

       

                for (int i = 0; i < 9; i++)

                {

                    X_0[i] = new Label();

                    X_0[i].Location = new Point(x, y);

                    X_0[i].Size = new Size(60, 60);

                    X_0[i].Text = "";

                    X_0[i].AutoSize = false;

                    X_0[i].BorderStyle = BorderStyle.Fixed3D;

                    X_0[i].BackColor = Color.Yellow;

                    X_0[i].Font = new Font("Arial", 40F);

                    X_0[i].TextAlign = ContentAlignment.MiddleCenter;

                    X_0[i].Tag = i;

                    X_0[i].Click += new System.EventHandler(Button_Click);

                    Controls.Add(X_0[i]);

                    x += 75;

                    if (i == 2 || i==5) { x = 15; y += 75; }

                    position[i] = false;

                  }

              

        

        }

        

        int q=0;

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)

        {

            Graphics gr = e.Graphics;

            Pen myPen = new Pen(Color.Red, 3);

            Point one = new Point(40, 15);

            Point two = new Point(40, 200);

            gr.DrawLine(myPen, one, two);

        }

    

        void Button_Click(object sender, EventArgs e)

        {

            Label lclick = (Label)sender;

            int n = Convert.ToInt32(lclick.Tag);

            Random x = new Random();

            bool downl = true;

          

            if (!position[n])

              {

                    X_0[n].Text = "X";

                    position[n] = true;

                    if (q != 4)

                    {

                        while (downl)

                        {

                            int y = x.Next(0, 9);

                            if (!position[y])

                            {

                                X_0[y].Text = "0";

                                position[y] = true;

                                downl = false;

                                q++;

                            }

                        }

                    }      

                }

            

            }   

}







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users