Note that there are some explanatory texts on larger screens.

plurals
  1. POPictureBox Runtime Image
    primarykey
    data
    text
    <p>To see the problems, please follow these steps (I am coding in C#):</p> <ol> <li>Put a picturebox on a form named picturebox1</li> <li>Resize it to small rectangle (say 75,75)</li> <li>Add a picture to resources (named say pic) larger than that rectangle (say 500,500)</li> </ol> <p>Now we are ready :D</p> <p>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:</p> <ol> <li>Adding Imagelist and setting size (this is not good at all)</li> <li>Writing onPaint of that picturebox something like this:</li> </ol> <blockquote> <p>e.Graphics.DrawImage(Properties.Resources.pic, new Rectangle(0,0,75,75));</p> </blockquote> <p>Lets assume that I want to fill the Image property of the picturebox1, now I must write something like this:</p> <blockquote> <p>pictureBox1.Image = (Image)Properties.Resources.ResourceManager.GetObject("pic1");</p> </blockquote> <p>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</p> <ol> <li><a href="http://www.google.com/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CBMQFjAA&amp;url=http%3A%2F%2Fwww.switchonthecode.com%2Ftutorials%2Fcsharp-tutorial-image-editing-saving-cropping-and-resizing&amp;ei=77FsTe-AOdCUswaPk_W1BQ&amp;usg=AFQjCNFUWSE3JC-UrqF6pUwaPmm9XMy6bQ" rel="nofollow">Image Editing Using C#</a></li> <li><a href="http://www.google.com/url?sa=t&amp;source=web&amp;cd=2&amp;ved=0CBoQFjAB&amp;url=http%3A%2F%2Fsnippets.dzone.com%2Fposts%2Fshow%2F4336&amp;ei=77FsTe-AOdCUswaPk_W1BQ&amp;usg=AFQjCNGW6Xs9uEQSJNnD__W-Mf7ntAWc5g" rel="nofollow">Image Editing while maintaining aspect ratio</a></li> </ol> <p>Now the second question:</p> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload