Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1052099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:02:21+00:00 2026-05-16T17:02:21+00:00

Firstly: apologies if this is a duplicate post. Things got a bit confusing as

  • 0

Firstly: apologies if this is a duplicate post. Things got a bit confusing as I’m trying to post/register at same time.

I started investigating running UCI chess engines from a simple WPF window, got the hang of having the chess engine running onf a different thread to the interface, and have created a reasonably servcieable text-based front end.

I’m getting a bit more ambitious now, and would like to start building a GUI with chess pieces on it that will feed the player’s moves to the chess engine, and represent the engine’s moves on the board as well. I’m aiming for draggable pieces rather than clicking squares.

My current attempts involve using draggable user controls for the pieces on a <canvas> element. I’d be really interested to hear how other, more experienced WPF/.NET programmers would approach this, as I’m not entirely convinced I’m on the right track.

For example: would it be better to use a uniform grid and drag piece data between child elements? Should I create an abstract ‘piece’ class from which pieces such as pawns could derive? That kind of thing.

Any thoughts? This isn’t a homework assignment or anything, just something I’m noodling around with in my spare time as an exercise.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:02:22+00:00Added an answer on May 16, 2026 at 5:02 pm

    I have implemented a chess board for my Silverlight Online Chess system.

    Here is how I did it.

    1. I made a seperate user control for the chess board
    2. I added a grid 8×8 onto the control
    3. I then added 64 Borders shading each one a different color (dark squares and light squares) Make sure to name each one. Each of the borders were placed on the grid using the Grid.Row and Grid.Col properties.
    4. Within each Border I added an Image that will hold the chess piece image.
    5. You will have to code some methods around setting the image to the correct chess piece based on your current game state.
    6. Each of the Images received the same event (this is important), all 64 call the same piece of code:

      MouseLeftButtonDown=”Image_MouseLeftButtonDown”
      MouseMove=”Image_MouseMove”
      MouseLeftButtonUp=”Image_MouseLeftButtonUp”

    The idea behind these 3 events is that we record when I click on the image (MouseLeftButtonDown) that gets me the origin of the click, then I call the event as the mouse is moving, that allows me to update the screen as the piece is moving, and the last event I record when I let go of the mouse button (MouseLeftButtonUp), this allows me to get the destination and send the move to my chess engine. Once the move is recorded by the chess engine I just redraw the chess board.

    private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        Image image = (Image)sender;
        Border border = (Border)image.Parent;
    
        image.CaptureMouse();
        isMouseCapture = true;
        mouseXOffset = e.GetPosition(border).X;
        mouseYOffset = e.GetPosition(border).Y;
    
        var chessPiece = (Image) sender;
        var chessSquare = (Border) chessPiece.Parent;
    
        var row = (byte) (Grid.GetRow(chessSquare));
        var column = (byte) (Grid.GetColumn(chessSquare) - 1);
    
        if (engine.HumanPlayer == ChessPieceColor.White)
        {
            SelectionChanged(row, column, false);
        }
        else
        {
            SelectionChanged((byte)(7 - row), (byte)(7 - column), false);
        }
    }
    

    SelectionChanged is my own method for recording what source square the user selected.
    isMouseCapture is also my own variable for recording when the user started draging the piece.

    private void Image_MouseMove(object sender, MouseEventArgs e)
    {
    
        Image image = (Image)sender;
        Border border = (Border)image.Parent;
    
    
        if (!currentSource.Selected)
        {
            image.ReleaseMouseCapture();
            isMouseCapture = false;
    
            translateTransform = new TranslateTransform();
    
            translateTransform.X = 0;
            translateTransform.Y = 0;
    
            mouseXOffset = 0;
            mouseYOffset = 0;
        }
    
    
    
        if (isMouseCapture)
        {
            translateTransform = new TranslateTransform();
    
            translateTransform.X = e.GetPosition(border).X - mouseXOffset;
            translateTransform.Y = e.GetPosition(border).Y - mouseYOffset;
    
            image.RenderTransform = translateTransform;
    
            CalculateSquareSelected((int)translateTransform.X, (int)translateTransform.Y, false);
    
    
        }
    }
    

    In the above CalculareSquareSelected converts the pixels moved to where I think the piece is moving to in the 8×8 chess board. For example say I moved 100 pixels and the chess board square is only 50 pixels than I moved 2 chess board squares.

    private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        if (translateTransform == null)
        {
            return;
        }
    
        Image image = (Image)sender;
    
        image.ReleaseMouseCapture();
        isMouseCapture = false;
    
        if (translateTransform.X > 10 || translateTransform.Y > 10 || translateTransform.X < -10 || translateTransform.Y < -10)
        {
            CalculateSquareSelected((int)translateTransform.X, (int)translateTransform.Y, true);
        }
        translateTransform = new TranslateTransform();
    
        translateTransform.X = 0;
        translateTransform.Y = 0;
    
        mouseXOffset = 0;
        mouseYOffset = 0;
    
        image.RenderTransform = translateTransform;
    
    }
    

    If you have any questions feel free to contact me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly apologies if this is really simple but I have spent hours trying and
Frstly my apologies if this is a duplicate question. I have tried to find
Firstly, YES, this is a duplicate issue that's been asked 100 times on here,
Firstly apologies if this a very basic question, I'm just curious to know the
Firstly, appologies if i get any terminology wrong on the upcoming post, this is
Firstly I want to tell you a bit about the background. I've got a
Possible Duplicate: In Java, what does a reference to Class.class do? Firstly apologies for
Firstly apologies for the length of this question, and for asking about the Facebook
Firstly apologies if this is a really simple question but Git is absolutely brand
Firstly apologies I've re-edited this as the original was so vague. What I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.