Click here to Skip to main content
15,892,005 members
Articles / Web Development / ASP.NET
Article

Easy-to-use Web ASP.NET Chessboard Control

Rate me:
Please Sign up or sign in to vote.
3.30/5 (4 votes)
14 Sep 20072 min read 40.3K   1.1K   14   2
An article to help you create a chessboard on ASP.NET using VB.NET
Screenshot - Chessboardcontrol_Gideonlouw.gif

Introduction

I searched many websites to find an easy website control chessboard to use, but could not find any. So, I have created a very easy to use chessboard control myself. Most other source code uses GDI graphics and Windows Forms. The logic I've used here is very easy and anybody can use it on a website. You only need .NET installed and you can copy the user control on any page.

Please note that I haven't added any logic to the control, but this can easily be built in if you want it.

Using the Code

The logic I've used to build the control is fairly simple. Firstly, create a table with 8 columns and 8 rows. Color-code the table into blocks with white blocks and black blocks. Now create 64 PANELS and 64 IMAGE CONTROLS. On your load event, set the images of the start-up position in chess and set those panels' visibility all to true. For all the other panels, set the visibility to false. To let the actual pieces move, you need to store the MoveFrom square and the MoveTo square:

VB
Dim MoveTo As Integer
MoveTo = CheckBoxNr
Dim MoveFrom As Integer
MoveFrom = lblMove.Text
If MoveTo = MoveFrom Then
    'No Move Take Place
    GoToEndSection
End If

Once you get the MoveFrom and MoveTo squares, you can execute a move. Currently, I haven't built in any code to evaluate if the move is correct. This board assumes the user knows how to move chess pieces, but this additional code can easily be inserted in the procedure that I've dimmed out, called PROCEDUREVALIDATEMOVE(MoveFrom,MoveTo).

Summary

So, to give a summary of the chessboard ASP.NET control: It is an HTML-type table with panels and images on each square, as well as a checkbox to check what piece moves to what square. I think this is the easiest and quickest way to create a chessboard that works on a website.

I hope this article can help you. If you want to, you can add a procedure to evaluate the piece moves to see if each move is correct before executing the move. If you make any changes to the code and updates, you are more than welcome to email me an updated copy of the source. Leave a message in the forum at the bottom of the article to get in touch.

History

  • 14 September, 2007 -- Original version posted

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
South Africa South Africa
Gideon Louw is a qualified MCSD and software professional.

He developed several industrial and government related applications that has successfully been installed all over the world.

Comments and Discussions

 
Questionneed help Pin
sainipraveen0421-Sep-07 6:29
sainipraveen0421-Sep-07 6:29 
AnswerRe: need help Pin
Louwgi24-Sep-07 21:38
Louwgi24-Sep-07 21:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.