私人形象包含在一个类中

时间:2013-04-02 05:30:50

标签: c# winforms class

好吧所以我正在做一个程序,希望随机选择一个游戏并根据该类显示信息。所以现在我有

namespace Twitch_Roulette
{
    class GameClass
    {
        private string gameName;
        private string developer;
        private string publisher;
        private string releaseDate;
        private string platform;
        private string genre;
        private string numPlayers;
        private string description;
    }
}

接下来我想要包含一个将成为游戏盒子的图像,但我该怎么做呢?

3 个答案:

答案 0 :(得分:2)

namespace Twitch_Roulette
{
    class GameClass
    {
        private string gameName;
        private string developer;
        private string publisher;
        private string releaseDate;
        private string platform;
        private string genre;
        private string numPlayers;
        private string description;
        private Image boxArt;
    }
}

Image类驻留在System.Drawing中,您可能必须在文件顶部使用using语句。

using System.Drawing;

答案 1 :(得分:1)

你可以像这样访问这个类:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        GameClass gameclass = new GameClass();
        gameclass.GameName = "Name of Game";
        gameclass.GameGenre = GameClass.Genre.RPG;
        //Add the rest of the fields here.
    }
}

GameClass类看起来像这样:

class GameClass
{
    public enum Genre
    {
        RPG,
        MMO,
        RTS,
        Other
    }

    public enum Platform
    {
        Windows,
        Linux,
        MAC
    }

    private string gameName;
    private string developer;
    private string publisher;
    private DateTime releaseDate;
    private Platform platform;
    private Genre genre;
    private int numPlayers;
    private string description;
    private Bitmap picture;

    public string GameName
    {
        get
        {
            return gameName;
        }
        set
        {
            gameName = value;
        }
    }

    public Genre GameGenre
    {
        get
        {
            return genre;
        }
        set
        {
            genre = value;
        }
    }

    //... Other get set methods
}

答案 2 :(得分:0)

这很简单(System.Drawing.dll必须包含在您的参考文献中):

class GameClass
{
    //your fields

    private System.Drawing.Bitmap image;
}