Исключение System.ArgumentException
В Winforms хочу нарисовать поле для игры. Имеется абстрактный класс клетки, от которого наследуются все элементы поля.
Класс Cell
public abstract class Cell
{
public string Path;
public Image Image;
public Cell(string path)
{
Path = path;
Image = new Bitmap(Path);
}
public virtual void Draw(Graphics gr, int j, int i, int side, int x, int y)
{
gr.DrawImage(this.Image, j * side + x, i * side + y, new Rectangle(new Point(0, 0), new Size(side, side)), GraphicsUnit.Pixel);
}
}
Класс наследник
class Empty : Cell
{
public Empty() : base($"../../Resources/grass.jpg") { }
}
Не могу понять, в чём ошибка. Почему "Недопустимый параметр"?
Ответы (1 шт):
Автор решения: Igor
→ Ссылка
public Cell(string path)
{
Path = path;
if (string.IsNullOrEmpty(Path))
throw Exception("Path to cell image is null or empty.");
if (!File.Exists(Path))
throw Exception("File of cell image does not exist: " + Path);
Image = new Bitmap(Path);
}
