On Thu, 06 Mar 2008 12:24:57 -0800, <za***@construction-imaging.comwrote:
Not "automatic" but it has the distinct advantage of working.
picturebox.Controls.Clear();
this.Height = this.Height + (usercontrol.Height - picturebox.Height);
this.Width = this.Width + (usercontrol.Width - picturebox.Width);
picturebox.Height = usercontrol.Height;
picturebox.Width = usercontrol.Width;
picturebox.Controls.Add(usercontrol);
this.CenterToScreen();
But again, why are you using a PictureBox? Why not use a more appropriate
control that already implements this automatic behavior?
Even if you want a PictureBox in there somewhere, for the purpose of
displaying an image, there's no need to make the PictureBox the container
itself. Use a real container, and put into it both the PictureBox and
your UserControl. You can even have the PictureBox anchored so that it
resizes as necessary as the container resizes according to the size of the
UserControl. And depending on how you want the image displayed, you could
simply set the background image for the container control and not bother
with a PictureBox at all.
You seem to be implementing very awkward code for no good reason. At the
very least, if there's really a good reason for using a PictureBox, it
would help to understand your question better if you could explain what
that reason is.
Pete