Click here to Skip to main content
Click here to Skip to main content

Easy-to-use Web ASP.NET Chessboard Control

, 14 Sep 2007
Rate this:
Please Sign up or sign in to vote.
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:

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

Share

About the Author

Louwgi
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 Pinmembersainipraveen0421-Sep-07 6:29 
AnswerRe: need help PinmemberLouwgi24-Sep-07 21:38 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 14 Sep 2007
Article Copyright 2007 by Louwgi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid