1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace qumo { public partial class Form1 : Form { private bool flag; private Rectangle[,] rectangles; private bool[,] myColors; private Point point = new Point(45, 15); private Color brushColor;
void RectangleInit() { myColors = new bool[8, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { myColors[i, j] = false; } } rectangles = new Rectangle[8, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { rectangles[i, j].Height = 25; rectangles[i, j].Width = 25; rectangles[i, j].X = point.X + 25 * i; rectangles[i, j].Y = point.Y + 25 * j; } } }
public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { RectangleInit(); this.flag = false; brushColor = Color.FromArgb(255, 0, 0); rbtnRed.Checked = true; }
private void Form1_MouseDown(object sender, MouseEventArgs e) { this.flag = true; }
private void Form1_MouseMove(object sender, MouseEventArgs e) { if (flag) { Graphics g = CreateGraphics(); try { if (e.X >= point.X && e.X < 200+point.X && e.Y >= point.Y && e.Y < 200+point.Y) { int tempX = (e.X - point.X) / 25; int tempY = (e.Y - point.Y) / 25; g.FillRectangle(new SolidBrush(brushColor), rectangles[tempX, tempY]); if (!brushColor.Equals(Color.Black)) { myColors[tempX, tempY] = true; } else { myColors[tempX, tempY] = false; } } } catch { }
for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { g.DrawRectangle(new Pen(Color.White), rectangles[i, j]); } } } }
private void Form1_MouseUp(object sender, MouseEventArgs e) { this.flag = false; }
private void Form1_Paint(object sender, PaintEventArgs e) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { e.Graphics.FillRectangle(new SolidBrush(Color.Black), rectangles[i, j]); } }
for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { e.Graphics.DrawRectangle(new Pen(Color.White), rectangles[i, j]); } }
}
private void button1_Click(object sender, EventArgs e) { var frm = new Form2(); frm.color = myColors; frm.Show(); }
private void rbtnBlue_CheckedChanged(object sender, EventArgs e) { brushColor = Color.Blue; }
private void rbtnRed_CheckedChanged(object sender, EventArgs e) { brushColor = Color.Red; }
private void rbtnBlack_CheckedChanged(object sender, EventArgs e) { brushColor = Color.Black; }
} }
|