易于使用的Web ASP.NET棋盘控件(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/easy-to-use-web-asp-net-chessboard-control-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 3 分钟阅读 - 1367 个词 阅读量 0易于使用的Web ASP.NET棋盘控件(译文)
原文地址:https://www.codeproject.com/Articles/20498/Easy-to-use-Web-ASP-NET-Chessboard-Control
原文作者:Louwgi
译文由本站 robot-v1.0 翻译
前言
An article to help you create a chessboard on ASP.NET using VB.NET
一篇文章,可帮助您使用VB.NET在ASP.NET上创建棋盘
介绍(Introduction)
我搜索了许多网站,以找到易于使用的网站控制棋盘,但找不到任何棋盘.因此,我自己创建了一个非常易于使用的棋盘控件.大多数其他源代码使用GDI图形和Windows窗体.我在这里使用的逻辑非常简单,任何人都可以在网站上使用它.您只需要安装.NET,就可以在任何页面上复制用户控件.(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)
我用来构建控件的逻辑非常简单.首先,创建一个具有8列8行的表.将表颜色编码为带有白色块和黑色块的块.现在创建64个面板和64个图像控件.在加载事件中,在国际象棋中设置启动位置的图像,并将这些面板的可见性全部设置为(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)
因此,总结一下棋盘的ASP.NET控件:它是一个HTML类型的表,每个正方形上都有面板和图像,还有一个复选框,用于检查哪个棋子移动到哪个正方形.我认为这是创建可在网站上使用的棋盘的最简单,最快的方法.(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)
- 2007年9月14日-发布原始版本(14 September, 2007 – Original version posted)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VB .NET Windows Visual-Studio WebForms ASP.NET Dev 新闻 翻译