بسم الله الرحمن الرحيم
هذه أول مشاركة لي في المنتدى و أتمنى أن أكون عضو فاعل في المستقبل...
أرجو المساعدة في رسم رقعة شطرنج باستخدام "GDI+"
بسم الله الرحمن الرحيم
هذه أول مشاركة لي في المنتدى و أتمنى أن أكون عضو فاعل في المستقبل...
أرجو المساعدة في رسم رقعة شطرنج باستخدام "GDI+"
السلام عليكم ..
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ArabTeamCS
{
/// <summary>
/// Description of Form3.
/// </summary>
public partial class Form3 : Form
{
public Form3()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
int _boardX = 10, _boardY = 10;
int _boardWidth = 240, _boardHeight = 240;//must be multiple of 8
Brush _borderColor = Brushes.Black;
Brush[] _boardColor = {Brushes.Gold, Brushes.Red};
void DrawChessBoard(Graphics g)
{
//draw squares
int spacingX = _boardWidth / 8;
int spacingY = _boardHeight / 8;
for(int col = 0; col < 8; col++)
{
for(int row = 0; row < 8; row++)
{
g.FillRectangle(_boardColor[(col + row) % 2], _boardX + col * spacingX, _boardY + row * spacingY, spacingX, spacingY);
}
}
for (int i = 0; i < 8; i++)
{
//draw lines
g.DrawLine(new Pen(_borderColor), _boardX, _boardY + i * spacingY, _boardX + _boardWidth, _boardY + i * spacingY);
g.DrawLine(new Pen(_borderColor), _boardX + i * spacingX, _boardY, _boardX + i * spacingX, _boardY + _boardHeight);
}
//draw border
g.DrawRectangle(new Pen(_borderColor, 1), new Rectangle(_boardX, _boardY, _boardWidth, _boardHeight));
//next you would draw pieces with an array of where they are
//assuming you have a ChessPiece class you could do something like this
/*
foreach(ChessPiece piece in pieces)
{
g.DrawImage(piece.img, piece.x, piece.y)
}
*/
}
void Form3Paint(object sender, PaintEventArgs e)
{
DrawChessBoard(e.Graphics);
}
}
}تم تعديل هذه المشاركة بواسطة houssam11350_11350 في 26 أبريل 2012 في 21:42
لا إله إلا الله ... محمد رسول الله
لو كانت مشاركتي مفيدة و تريد تشجيعي على المزيد من العطاء , فضلا قم بتقييم المشاركة
المعرًف القديم : houssam11350_11350
من مواضيعي : ArabGenCode : مولد كود و إجراءات مخزنة و واجهات لجداول سيكوال سيرفر
مشكور يا أخي