C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2712
Number of posts: 5738

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Drawing Line over Form and labels Posted by Abbath on 29 Mar 2011 at 8:21 PM
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++;
                            }
                        }
                    }      
                }
            
            }   
}


Report
Re: Drawing Line over Form and labels Posted by tozmer on 5 May 2011 at 1:18 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.