If you are talking about automatic resize of any control, you can usually have it docked to some other control like
Panel
(or a
Form
,
TabPage
and others) which itself would be resized. You need to use
Dock
property with the value
System.Windows.Forms.DockStyle.Fill
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle.aspx[
^].
Anchors would work, too, but usually
Dock
with
Padding
is much better. See also:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.padding.aspx[
^].
However, I don't sure that you really need to resize
PictureBox
. Most likely, you should not use this control at all. It is totally redundant (you can implement it using the same API) and only needed to simplify the simplest chores (static image of fixed size and so on). It becomes a hassle when you try to do anything even a tiny bit more complex. In your case, the problem would be resampling of the image.
(By the way, you should understand that resampling an image up its quality unacceptable. You can only make it smaller than original, or only slightly bigger. unless you agree to make it ugly looking.)
So, not using
PictureBox
could be better than using it. Please see my past answers:
Append a picture within picturebox[
^],
draw a rectangle in C#[
^],
How do I clear a panel from old drawing[
^].
And also:
capture the drawing on a panel[
^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[
^],
How to speed up my vb.net application?[
^],
Drawing Lines between mdi child forms[
^].
I hope it will explain the simple techniques you need to understand.
—SA