Automatically Resize Form?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zacks@construction-imaging.com

    Automatically Resize Form?

    I am developing an application in VS2005. I have a form that has a
    PictureBox control whose purpose is to be able to plop a User Control
    in it. And the User Control can be one of several possible User
    Controls and these User Controls are all different in size, some
    larger that the picture box it will be added to.

    How do I get the form to resize when I add a User Control to the
    picture box control when the User Control is larger than the picture
    box?
  • Peter Duniho

    #2
    Re: Automatically Resize Form?

    On Thu, 06 Mar 2008 09:43:26 -0800, <zacks@construc tion-imaging.comwrot e:
    I am developing an application in VS2005. I have a form that has a
    PictureBox control whose purpose is to be able to plop a User Control
    in it. And the User Control can be one of several possible User
    Controls and these User Controls are all different in size, some
    larger that the picture box it will be added to.
    >
    How do I get the form to resize when I add a User Control to the
    picture box control when the User Control is larger than the picture
    box?
    Why are you using a PictureBox? That's wholly inappropriate as a
    container control.

    If you were using a proper container control, you'd have the AutoSize and
    AutoSizeMode properties that would allow you to do this automatically.
    Just set AutoSize to true and AutoSizeMode to AutoSizeMode.Gr owAndShrink.
    Then as items are added or removed from the control, it will resize
    appropriately.

    Pete

    Comment

    • Peter Duniho

      #3
      Re: Automatically Resize Form?

      On Thu, 06 Mar 2008 12:24:57 -0800, <zacks@construc tion-imaging.comwrot e:
      Not "automatic" but it has the distinct advantage of working.
      >
      picturebox.Cont rols.Clear();
      this.Height = this.Height + (usercontrol.He ight - picturebox.Heig ht);
      this.Width = this.Width + (usercontrol.Wi dth - picturebox.Widt h);
      picturebox.Heig ht = usercontrol.Hei ght;
      picturebox.Widt h = usercontrol.Wid th;
      picturebox.Cont rols.Add(userco ntrol);
      this.CenterToSc reen();
      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

      Comment

      • Joe Cool

        #4
        Re: Automatically Resize Form?

        On Thu, 06 Mar 2008 10:04:53 -0800, "Peter Duniho"
        <NpOeStPeAdM@nn owslpianmk.comw rote:
        >On Thu, 06 Mar 2008 09:43:26 -0800, <zacks@construc tion-imaging.comwrot e:
        >
        >I am developing an application in VS2005. I have a form that has a
        >PictureBox control whose purpose is to be able to plop a User Control
        >in it. And the User Control can be one of several possible User
        >Controls and these User Controls are all different in size, some
        >larger that the picture box it will be added to.
        >>
        >How do I get the form to resize when I add a User Control to the
        >picture box control when the User Control is larger than the picture
        >box?
        >
        >Why are you using a PictureBox? That's wholly inappropriate as a
        >container control.
        >
        >If you were using a proper container control, you'd have the AutoSize and
        >AutoSizeMode properties that would allow you to do this automatically.
        >Just set AutoSize to true and AutoSizeMode to AutoSizeMode.Gr owAndShrink.
        >Then as items are added or removed from the control, it will resize
        >appropriatel y.
        What control would be a "proper container control"? Panel?

        Comment

        Working...