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 checkboard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics GraphicsObj;
GraphicsObj = this.CreateGraphics();//e.Graphics在Form1_Paint中可以用
Pen myPen = new Pen(System.Drawing.Color.Gray,1);
//x1,y1,x2,y2
int i,j;
for (i = 0; i <= 300;i =i + 30)
for (j = 0; j <= 300;j = j + 30)
GraphicsObj.DrawRectangle(myPen,i, j, 30, 30);//画矩形
int x, y, m = 50, n = 50;//输入位置坐标
x = m / 30 * 30;
y = n / 30 * 30;
if (x <= 90 && y <= 60)
{
GraphicsObj.DrawRectangle(myPen, x, y, 30, 30);//画矩形
GraphicsObj.FillRectangle((Brush)Brushes.Red, x, y, 30, 30);
}
else if (x >= 90 && y >= 150 && y <= 240)
{
GraphicsObj.DrawRectangle(myPen, x, y, 30, 30);//画矩形
GraphicsObj.FillRectangle((Brush)Brushes.Yellow, x, y, 30, 30);
}
else
{
GraphicsObj.DrawRectangle(myPen, x, y, 30, 30);//画矩形
GraphicsObj.FillRectangle((Brush)Brushes.White, x, y, 30, 30);
}
GraphicsObj.DrawEllipse(myPen, m, n, 10, 10);//画圆
GraphicsObj.FillEllipse((Brush)Brushes.Green, m, n, 10,10);
}
private void button1_Click(object sender, EventArgs e)
{
System.Drawing.Graphics GraphicsDra;
GraphicsDra = this.CreateGraphics();//e.Graphics在Form1_Paint中可以用
Pen rePen = new Pen(System.Drawing.Color.Black, 1);
//x1,y1,x2,y2
GraphicsDra.DrawRectangle(rePen, 0, 0, 30, 30);//画矩形
int x, y, m = 220, n = 250;
x = m / 30 * 30;
y = n / 30 * 30;
if (x <= 90 && y <= 60)
{
GraphicsDra.DrawRectangle(rePen, x, y, 30, 30);//画矩形
GraphicsDra.FillRectangle((Brush)Brushes.Red, x, y, 30, 30);
}
else if (x >= 90 && y >= 150 && y <= 240)
{
GraphicsDra.DrawRectangle(rePen, x, y, 30, 30);//画矩形
GraphicsDra.FillRectangle((Brush)Brushes.Yellow, x, y, 30, 30);
}
else
{
GraphicsDra.DrawRectangle(rePen, x, y, 30, 30);//画矩形
GraphicsDra.FillRectangle((Brush)Brushes.White, x, y, 30, 30);
}
GraphicsDra.DrawEllipse(rePen, m, n, 10, 10);//画圆
GraphicsDra.FillEllipse((Brush)Brushes.Green, m, n, 10, 10);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace checkboard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics GraphicsObj;
GraphicsObj = this.CreateGraphics();//e.Graphics在Form1_Paint中可以用
Pen myPen = new Pen(System.Drawing.Color.Gray,1);
//x1,y1,x2,y2
int i,j;
for (i = 0; i <= 300;i =i + 30)
for (j = 0; j <= 300;j = j + 30)
GraphicsObj.DrawRectangle(myPen,i, j, 30, 30);//画矩形
int x, y, m = 50, n = 50;//输入位置坐标
x = m / 30 * 30;
y = n / 30 * 30;
if (x <= 90 && y <= 60)
{
GraphicsObj.DrawRectangle(myPen, x, y, 30, 30);//画矩形
GraphicsObj.FillRectangle((Brush)Brushes.Red, x, y, 30, 30);
}
else if (x >= 90 && y >= 150 && y <= 240)
{
GraphicsObj.DrawRectangle(myPen, x, y, 30, 30);//画矩形
GraphicsObj.FillRectangle((Brush)Brushes.Yellow, x, y, 30, 30);
}
else
{
GraphicsObj.DrawRectangle(myPen, x, y, 30, 30);//画矩形
GraphicsObj.FillRectangle((Brush)Brushes.White, x, y, 30, 30);
}
GraphicsObj.DrawEllipse(myPen, m, n, 10, 10);//画圆
GraphicsObj.FillEllipse((Brush)Brushes.Green, m, n, 10,10);
}
private void button1_Click(object sender, EventArgs e)
{
System.Drawing.Graphics GraphicsDra;
GraphicsDra = this.CreateGraphics();//e.Graphics在Form1_Paint中可以用
Pen rePen = new Pen(System.Drawing.Color.Black, 1);
//x1,y1,x2,y2
GraphicsDra.DrawRectangle(rePen, 0, 0, 30, 30);//画矩形
int x, y, m = 220, n = 250;
x = m / 30 * 30;
y = n / 30 * 30;
if (x <= 90 && y <= 60)
{
GraphicsDra.DrawRectangle(rePen, x, y, 30, 30);//画矩形
GraphicsDra.FillRectangle((Brush)Brushes.Red, x, y, 30, 30);
}
else if (x >= 90 && y >= 150 && y <= 240)
{
GraphicsDra.DrawRectangle(rePen, x, y, 30, 30);//画矩形
GraphicsDra.FillRectangle((Brush)Brushes.Yellow, x, y, 30, 30);
}
else
{
GraphicsDra.DrawRectangle(rePen, x, y, 30, 30);//画矩形
GraphicsDra.FillRectangle((Brush)Brushes.White, x, y, 30, 30);
}
GraphicsDra.DrawEllipse(rePen, m, n, 10, 10);//画圆
GraphicsDra.FillEllipse((Brush)Brushes.Green, m, n, 10, 10);
}
}
}