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 3450892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:05:36+00:00 2026-05-18T09:05:36+00:00

I wrote some code to move the king in chess game; can you tell

  • 0

I wrote some code to move the king in chess game; can you tell me where is the problem of this code that king doesn’t move? Thanks.

EDITED2:

public partial class Form1 : Form
{
    PictureBox[,] pic = new PictureBox[8, 8];

private void pictureBox34_Click(object sender, EventArgs e)
    {

if (pictureBox34.Image == chess9.Properties.Resources.siyahsah2)

{

f();
}
}

public void picarray()
{
        pic[0, 0] = pictureBox54;
        pic[0, 1] = pictureBox64;
        pic[0, 2] = pictureBox48;
        pic[0, 3] = pictureBox42;
        pic[0, 4] = pictureBox34;
        pic[0, 5] = pictureBox26;
        pic[0, 6] = pictureBox18;
        pic[0, 7] = pictureBox8;
        pic[1, 0] = pictureBox1;
        pic[1, 1] = pictureBox2;
        pic[1, 2] = pictureBox3;
        pic[1, 3] = pictureBox4;
              .
              .///thats so long(64 arrays)
              .
 }

public void f()
{



        int x = 3;
        int y = 3;

       for (int i = 1; i < x; i++)
       {
            for (int j = 1; j < y; j++)
            {
                pic[i, j] = new PictureBox();

                pic[i, j] = pic[i + 1, j + 1];

                pic[i, j] = new PictureBox();
                pic[i, j].Image = Image.FromFile("pic/siyahsah2.jpg");

          }

}
}
  • 1 1 Answer
  • 0 Views
  • 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-18T09:05:36+00:00Added an answer on May 18, 2026 at 9:05 am

    No, you didn’t define the return types correctly, as you don’t have any return values at all anywhere in that code.

    Let’s see what the code might do…

    The first problem is this line:

    if (pictureBox34.Image == Image.FromFile("pic/siyahsah2.jpg"))
    

    The FromFile method will create a new object, and as that object will never be the same object as the one stored in the picture box, the condition is always false and the method f is never called.

    In the method picarray you are using the variable pic, but that won’t be the same variable as the one used in the f method, as that variable is declared locally in that method,

    In the f method you are declaring an array of picture boxes which you manipulate, but then you just exit the method without doing anything with the array, so the array just goes away and the result will never be visible anywhere.

    As the array is newly created, it contains only null referecens, so copying them from one item to another in the array doesn’t accomplish anything. You are also copying items from two positions into the same position, so the second copy will overwrite the first.

    As the variables i and j are set to zero, [i - 1, j - 1] will try to access an item that is outside the array, which would give you an exception.

    You are trying to store something in the Image property of one of the items in the array, but as all items in the array are null, there is no picture box that you can set the Image property of.

    It’s hard to tell what you are trying to do, but this information should at least help you to understand what the code doesn’t do.

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

Sidebar

Related Questions

I wrote some code with a lot of recursion, that takes quite a bit
I wrote some naive code(in the sense that it's synchronous calls) for a tableview
I recently wrote some javascript code that filled a drop down list based on
I recently wrote some code that uses the same unsigned short to store two
I have some existing code in C# that I'm trying to move to an
I'm trying to achieve this effect with jQuery. I wrote some of the code,
I wrote some code recently (ISO/ANSI C), and was surprised at the poor performance
I wrote some code to read a file in my Java Servlet class. (I'm
I just wrote some code to test the behavior of std::equal, and came away
I'm very new to C#. My boss asked me to wrote some code using

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.