Anybody know anything about the PictureBox control?

Ok I'm trying to derive from the picturebox control in System.Windows.Forms and set it to a default pic that can be changed via a setPic method.
It's supposed to be a blank box that changes to a red x when the user gets a question wrong...

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Fraction_Game
{
public class xBox : System.Windows.Forms.PictureBox
{
const byte a = 20;
public xBox()
{
this.Size = new Size(a, a);
this.setPic(true);
}

public void setPic(bool correct)
{
string path;
this.SizeMode = PictureBoxSizeMode.Normal;
if (correct)
{
path = @BlankX.BMP;
}
else
{
path = @RedX.BMP;
}
this.Image = Image.FromFile(path);
}
}

Every time I try to add the control to the form, I get a FileNotFoundException. It can't load the blankX.bmp file, which is in the same directory as the project, right clicked and selected "include in project" and everything. I have tried using various iterations of the file name... "~/BlankX.bmp" , @~/BlankX.bmp etc etc and nothing seems to work.
I can only assume there's some property of PictureBox that I'm unaware of that I need to set? nothing that I can figure out.

Anyone?

Comments

  • Without yet looking into what problem you might be encountering I wanted to ask why you weren't loading your images into a resource file and the just setting the image property to the resource image you want - this creates a static reference to a static image object that can be accessed anywhere in your assembly and helps avoid creating an abundance of Image objects that need to be later sent to garbage collection. It also makes less files that must be distributed with your assembly which reduces the number of potential errors you may be encountering (for example if someone installs your application and then runs it with an altered default file directory)
    ><//~Psightoplasm`~
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion