using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Drawing; namespace firstCSharp { class FirstForm : Form { public FirstForm() { BackColor = Color.Tomato; Text = "Hello world!"; Height = 600; const double GOLDEN_RATIO = 1.618; Width = (int) (Height * GOLDEN_RATIO); MouseClick += FirstForm_MouseClick; MouseMove += FirstForm_MouseMove; Paint += FirstForm_Paint; // Opacity = .5; } private void FirstForm_Paint(object sender, PaintEventArgs e) { // Draw a chessboard in the window. // Get the instance of class graphics that is associated // with the client area of this window. Graphics graphics = e.Graphics; // ClientRectangle can provide the size of the client area int width = ClientRectangle.Width; int height = ClientRectangle.Height; // Find the smaller of the two dimensions int squareSide = Math.Min(width, height); // Draw a square showing where the board will be graphics.DrawRectangle(Pens.Green, new Rectangle(new Point(0, 0), new Size(squareSide, squareSide))); graphics.FillRectangle(Brushes.Green, new Rectangle(new Point(0, 0), new Size(squareSide, squareSide))); const int N_ROWS = 8; const int N_COLUMNS = 8; Brush lightSquareBrush = Brushes.Bisque; Brush darkSquareBrush = Brushes.DarkGreen; Brush nextSquare = lightSquareBrush; int smallSquare = squareSide / N_ROWS; for(int row=0;row> 16) & 0x0000ffff; Console.WriteLine("xy coord is ({0}, {1})", x, y); break; } //if (m.Msg != WM_LBUTTONDOWN) { base.WndProc(ref m); } } private void FirstForm_MouseMove(object sender, MouseEventArgs e) { Text = String.Format("({0}, {1})", e.X, e.Y); } private void FirstForm_MouseClick(object sender, MouseEventArgs e) { if (BackColor == Color.Tomato) { BackColor = Color.Chartreuse; } else { BackColor = Color.Tomato; } } } }