我在使用动态创建的Resource(位图)时遇到问题。 我只想将图片框设置为动态创建的名为“ adam”的资源 我知道我可以使用
pictureBox1.Image = Properties.Resources.shot
,但我正在寻找使用方法
pictureBox1.Image = Properties.Resources+'adam'
我的代码如下:
Size shotSize = Screen.PrimaryScreen.WorkingArea.Size;
// the upper left point in the screen to start shot
// 0,0 to get the shot from upper left point
int x = Convert.ToInt32(textBox1.Text);
int y = Convert.ToInt32(textBox2.Text);
Point upperScreenPoint = new Point(x, y);
// the upper left point in the image to put the shot
Point upperDestinationPoint = new Point(0, 0);
int q = Convert.ToInt32(textBox3.Text) - x;
int w = Convert.ToInt32(textBox4.Text) - y;
// create image to get the shot in it
Bitmap shot = new Bitmap(q, w);
// new Graphics instance
Graphics graphics = Graphics.FromImage(shot);
// get the shot by Graphics class
graphics.CopyFromScreen(upperScreenPoint, upperDestinationPoint, shotSize);
// return the image
//pictureBox1.Image = shot;
//Creating My resource named 'adam'
IResourceWriter writer = new ResourceWriter("Resources.resx");
writer.AddResource("adam", shot);
writer.Close();
//Read resources
System.Resources.ResourceReader RRobj = new ResourceReader("Resources.resx");
foreach (DictionaryEntry d in RRobj)
{
textBox6.Text=(d.Key.ToString() + ":\t" + d.Value.ToString());
string huj = d.Key.ToString();
pictureBox1.Image = Properties.Resources + 'huj' +; // here set picturebox with reousce created
}
RRobj.Close();
有人可以帮忙吗? 谢谢。