To see the problems, please follow these steps (I am coding in C#):
- Put a picturebox on a form named picturebox1
- Resize it to small rectangle (say 75,75)
- Add a picture to resources (named say pic) larger than that rectangle (say 500,500)
Now we are ready :D
I know two ways to have this picture shown in the picturebox at runtime while showing the whole picture not only a part of it:
- Adding Imagelist and setting size (this is not good at all)
- Writing onPaint of that picturebox something like this:
e.Graphics.DrawImage(Properties.Resources.pic, new Rectangle(0,0,75,75));
Lets assume that I want to fill the Image property of the picturebox1, now I must write something like this:
pictureBox1.Image = (Image)Properties.Resources.ResourceManager.GetObject("pic1");
which does not resize the image retrieved. I want to know if there is a good way around this problem (to resize and assign easily)? BTW, I don't want to resize the picture using something like these
Now the second question:
I know resources are statically added in my example, but is there a way to get the name of the resource programmatically instead of hardcoding it as string and passing it to the "GetObject()" method?