未找到面板背景 [英] Panel background didn't found

查看:60
本文介绍了未找到面板背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在面板上有阵列面板(8x8)我已将backgroundImage与Proprietes.Ressource放在一起

我喜欢

PionNoir TourNoir ReineNoir RoiNoir,ChevalNoir FouNoir和

PionBlanc TourBlanc ReineBlanc RoiBlanc,ChevalBlanc FouBlanc



i不能喜欢的形象

但我想在面板上做一些特别的事情他有Imagebackground







Hello,

I have array Panel (8x8) on the panel i have put backgroundImage with Proprietes.Ressource
I have like
PionNoir TourNoir ReineNoir RoiNoir,ChevalNoir FouNoir and
PionBlanc TourBlanc ReineBlanc RoiBlanc,ChevalBlanc FouBlanc

i can't like image of that
But i wanted to do something special when on panel he have Imagebackground



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EchequeV2
{
    class Fou:Joueur
    {
        private int nbrPlaceY = 8;
        private int nbrPlaceX = 8;
        private int IndexeDiagonalY;
        private int IndexeDiagonalX;
        private int IndexeX;
        private int IndexeY;
        private List<Point> lstposition = new List<Point>();
        public Fou(string id, int y, int x) : base(id, y, x)
        {
            IndexeX = x;
            IndexeY = y;
            Reset();
        }
        private void loadData()
        {
            IndexeX = X;
            IndexeY = Y;
            lstposition = new List<Point>();
        }
        public override void Mouvement(Panel[,] tblPanel)
        {
            loadData();
            DiagonalDroite(tblPanel);
            for (int y = 0; y < nbrPlaceY; y++)
            {
                for (int x = 0; x < nbrPlaceX; x++)
                {
                    if (IndexeDiagonalX == x && IndexeDiagonalY == y)
                    {
                        lstposition.Add(new Point(x, y));
                        IndexeDiagonalY++;
                        IndexeDiagonalX--;
                    }
                }
            }

            DiagonalGauche(tblPanel);
            for (int y = 0; y < nbrPlaceY; y++)
            {
                for (int x = 0; x < nbrPlaceX; x++)
                {
                    if (IndexeDiagonalX == x && IndexeDiagonalY == y)
                    {
                        lstposition.Add(new Point(x, y));
                        IndexeDiagonalY++;
                        IndexeDiagonalX++;
                    }
                }
            }

            AffichageMouvement(lstposition, tblPanel);
        }
        private void AffichageMouvement(List<Point> lstPoint, Panel[,] tblPanel)
        {
            for (int i = 0; i < lstposition.Count; i++)
            {
                Point poDefault = new Point();

                poDefault.Y = lstposition[i].Y;
                poDefault.X = lstposition[i].X;
                if (poDefault.Y < 8 && poDefault.X < 8)
                    tblPanel[poDefault.Y, poDefault.X].BackColor = Color.Red;
            }


        }
        private void DiagonalDroite(Panel[,] tblPanel)
        {
            Reset();
            while (IndexeDiagonalY != 0 && IndexeDiagonalX != 8 - 1)
            {
                IndexeDiagonalX++;
                IndexeDiagonalY--;
            }
        }
        private void DiagonalGauche(Panel[,] tblPanel)
        {
            Reset();
            while (IndexeDiagonalY != 0 && IndexeDiagonalX != 0 )
            {
                IndexeDiagonalX--;
                IndexeDiagonalY--;
                if(ID.Contains("Blanc"))
                {
                    if (tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.PionBlanc ||
                        tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.ReineBlanc ||
                        tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.RoiBlanc ||
                        tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.ChevalBlanc ||
                        tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.Tour )
                    {
                        break;
                    }
                   
                }
                else
                {
                    if(tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage != null)
                    {
                        MessageBox.Show("Je suis la ");
                    }
                    if (tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.PionNoir ||
                        tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.ReineNoir ||
                        tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.RoiNoir ||
                        tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.ChevalNoir ||
                        tblPanel[IndexeDiagonalY, IndexeDiagonalX].BackgroundImage == Properties.Resources.TourNoir)
                    {

                        MessageBox.Show("JE SUIS VIVANTTTTTT ELED");
                    }
                }
               
            }
        }

        private void Reset()
        {
            IndexeDiagonalX = IndexeX;
            IndexeDiagonalY = IndexeY;
        }
    }
}





我尝试了什么:



我试图看看我的panel.backgroundimage他是否没有null这是有效但当我想看看它是否像pionNoir这样的图像时他没有看到它需要你帮助:(



What I have tried:

I have tried to see if my panel.backgroundimage he didn't null that's working but when i want to see if it's an image like pionNoir he didn't see it

i need you help :(

推荐答案

问题是当你从<检索图像时code> Properties.Resources 它创建了一个Image类的新实例,并用适当的Bitmap填充它。

因为Panel包含一个不同的实例相同的图像数据,它们不匹配(因为从技术上讲,你现在可以在面板版本上编写,这不会影响新加载的版本。

如果你想比较它们,需要在应用程序开始时从Resources加载每个图像,并将它们存储在Image变量中供以后使用和比较。

试一试:

The problem is that when you retrieve an image from Properties.Resources it creates a new instance of the Image class, and fills it with the appropriate Bitmap.
So because the Panel contains a different instance of the same image data, they do not match (because technically, you could have written on the panel version by now, and that would not have affected the newly loaded version.
If you want to compare them, the need to load each of the images from Resources at the start of your app, and store them in Image variable for later use and comparison.
Try it:
Image A = Properties.Resources.MyImage;
Image B = Properties.Resources.MyImage;
Console.WriteLine(A == B ? "Yes" : "No");

您将始终打印No。


这篇关于未找到面板背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆