从静态对象分配控件时不显示图像

Image doesn't display when control is assigned from static object

我正在使用 WinForms 在 C# 中制作纸牌游戏。我遇到的问题阻止我继续前进,因为我想添加用户制作的内容。目标是根据 resource/file 声明的内容动态地将图像设置为卡片。让我们看看我的代码。

这里是ExpansionInit.cs

public static Card CopperCard = new Card
{
    Name = "Copper",
    ID = 0,
    BuyValue = 0,
    Type = CardType.Treasure,
    TreasureValue = 1,
    StackCount = GetCardStack(0),
};

这里是GameGUI.cs

using System;
using System.Windows.Forms;
using Dominion.Expansions.Base;
using Dominion.Properties;

namespace Dominion
{
    public partial class GameGui : Form
    {

        public GameGui()
        {
            Game.StartGame();
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //new HandGUI().Show();
            cardCopper = ExpansionInit.CopperCard;
            cardCopper.BackgroundImage = Resources._0_copper;
        }
    }
}

这里是Card.cs。我不太确定包括这部分是否重要,但如果您能在其中找到可能导致问题的内容

using System.Windows.Forms;
using Newtonsoft.Json;

namespace Dominion.Cards
{
    public delegate void CardActivationHandler(Card c, Player p);
    [JsonObject(MemberSerialization.OptIn)]
    public sealed partial class Card : UserControl
    {
        // ReSharper disable once InconsistentNaming
        [JsonProperty]
        public int StackCount;
        [JsonProperty]
        public int ID;
        [JsonProperty]
        public int TreasureValue;
        [JsonProperty]
        public int VictoryValue;
        [JsonProperty]
        public int BuyValue;
        [JsonProperty]
        public CardType Type;
        [JsonProperty]
        public CardActivationHandler Handler;

        [JsonProperty]
        public new string Text { get; set; }

        [JsonProperty]
        public new string Name { get; set; }
        public Card()
        {
            InitializeComponent();
        }
    }

    public enum CardType
    {
        Victory, Treasure, Action, Other
    }
}

需要重新添加对象 form1.Controls.Add(cardCopper) 并重置位置。