您的位置:首页 > 编程语言 > C#

GDI绘制中国象棋棋盘

2014-04-04 22:01 351 查看
初学C#,自己写的棋盘,没什么技术含量,能达到预期效果就很开心了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace saolei
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
}

private void Form2_Paint(object sender, PaintEventArgs e)
{
int col1 = 5;
int row1 = 9;
int xPoint = 10;
int yPoint = 10;
Pen p = new Pen(Brushes.Black, 2);
p.DashStyle = DashStyle.Custom;
//绘制上半部分:4行
for (int i = 0; i < col1; i++)
{
e.Graphics.DrawLine(p, 10, yPoint, 410, yPoint);
yPoint += 50;
}
//画列
for (int i = 0; i < row1; i++)
{
e.Graphics.DrawLine(p, xPoint, 10, xPoint, yPoint - 50);
xPoint += 50;
}
//帅的家
Pen p1 = new Pen(Brushes.Red, 1);
p1.DashStyle = DashStyle.DashDot;
e.Graphics.DrawLine(p1, 160, 10, 260, 110);
e.Graphics.DrawLine(p1, 160, 110, 260, 10);
//中间的河
Font f1 = new Font("华文行楷", 30F, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Point, 134);
Brush bs1 = new SolidBrush(Color.Purple);
PointF hePoint = new PointF(20, 215);
string heStr = "   楚  河      汉  界    ";
e.Graphics.DrawString(heStr, f1, bs1, hePoint);
xPoint = 10;
//绘制下半部分
for (int i = 0; i < col1; i++)
{
e.Graphics.DrawLine(p, 10, yPoint, 410, yPoint);
yPoint += 50;
}
for (int i = 0; i < row1; i++)
{
e.Graphics.DrawLine(p, xPoint, 260, xPoint, 460);
xPoint += 50;
}
//绘制帅家
e.Graphics.DrawLine(p1, 160, 360, 260, 460);
e.Graphics.DrawLine(p1, 260, 360, 160, 460);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  gdi c#