PC Review


Reply
Thread Tools Rate Thread

Automatically Resize Form?

 
 
zacks@construction-imaging.com
Guest
Posts: n/a
 
      6th Mar 2008
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?
 
Reply With Quote
 
 
 
 
kimiraikkonen
Guest
Posts: n/a
 
      6th Mar 2008
On Mar 6, 7:43*pm, za...@construction-imaging.com wrote:
> 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?


If you're not talking about fitting picturebox on a form which that's
higher on screen / desktop resolution (which i'd like to accomplish),
and you might have mentioned about a kind of alignment / object
fitting issue, i think you should do:

Picurebox1.size = <User_control>.size ' Assuming user control
providing a GUI and size info.
' Apply the same for the form

Me.size = Picturebox1.size ' Or add some space "Picturebox1.size + 50"

Hope this helps.
 
Reply With Quote
 
 
 
 
kimiraikkonen
Guest
Posts: n/a
 
      6th Mar 2008
On Mar 6, 7:55*pm, kimiraikkonen <kimiraikkone...@gmail.com> wrote:
> On Mar 6, 7:43*pm, za...@construction-imaging.com wrote:
>
> > 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?

>
> If you're not talking about fitting picturebox on a form which that's
> higher on screen / desktop resolution (which i'd like to accomplish),
> and you might have mentioned about a kind of alignment / object
> fitting issue, i think you should do:
>
> Picurebox1.size = <User_control>.size ' Assuming user control
> providing a GUI and size info.
> ' Apply the same for the form
>
> Me.size = Picturebox1.size ' Or add some space "Picturebox1.size + 50"
>
> Hope this helps.


Note: Of course do this when you need it, so put them in a IF....Then
statment block.
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      6th Mar 2008
On Thu, 06 Mar 2008 09:43:26 -0800, <(E-Mail Removed)> wrote:

> 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.GrowAndShrink.
Then as items are added or removed from the control, it will resize
appropriately.

Pete

 
Reply With Quote
 
zacks@construction-imaging.com
Guest
Posts: n/a
 
      6th Mar 2008
On Mar 6, 12:55*pm, kimiraikkonen <kimiraikkone...@gmail.com> wrote:
> On Mar 6, 7:43*pm, za...@construction-imaging.com wrote:
>
> > 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?

>
> If you're not talking about fitting picturebox on a form which that's
> higher on screen / desktop resolution (which i'd like to accomplish),
> and you might have mentioned about a kind of alignment / object
> fitting issue, i think you should do:
>
> Picurebox1.size = <User_control>.size ' Assuming user control
> providing a GUI and size info.
> ' Apply the same for the form
>
> Me.size = Picturebox1.size ' Or add some space "Picturebox1.size + 50"
>
> Hope this helps.



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();
 
Reply With Quote
 
kimiraikkonen
Guest
Posts: n/a
 
      6th Mar 2008
On Mar 6, 10:24*pm, za...@construction-imaging.com wrote:
> On Mar 6, 12:55*pm, kimiraikkonen <kimiraikkone...@gmail.com> wrote:
>
>
>
>
>
> > On Mar 6, 7:43*pm, za...@construction-imaging.com wrote:

>
> > > 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?

>
> > If you're not talking about fitting picturebox on a form which that's
> > higher on screen / desktop resolution (which i'd like to accomplish),
> > and you might have mentioned about a kind of alignment / object
> > fitting issue, i think you should do:

>
> > Picurebox1.size = <User_control>.size ' Assuming user control
> > providing a GUI and size info.
> > ' Apply the same for the form

>
> > Me.size = Picturebox1.size ' Or add some space "Picturebox1.size + 50"

>
> > Hope this helps.

>
> 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();- Hide quoted text -
>
> - Show quoted text -


So did it work for you?
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      6th Mar 2008
On Thu, 06 Mar 2008 12:24:57 -0800, <(E-Mail Removed)> wrote:

> 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
 
Reply With Quote
 
Joe Cool
Guest
Posts: n/a
 
      6th Mar 2008
On Thu, 06 Mar 2008 10:04:53 -0800, "Peter Duniho"
<(E-Mail Removed)> wrote:

>On Thu, 06 Mar 2008 09:43:26 -0800, <(E-Mail Removed)> wrote:
>
>> 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.GrowAndShrink.
>Then as items are added or removed from the control, it will resize
>appropriately.


What control would be a "proper container control"? Panel?
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      7th Mar 2008
On Thu, 06 Mar 2008 14:55:59 -0800, Joe Cool <(E-Mail Removed)> wrote:

> What control would be a "proper container control"? Panel?


Sure. Or UserControl. Or a GroupBox. Or any other control that was
specific designed to act as a container for other controls All controls
support having child controls, but most are not actually intended to be
containers for other controls. The PictureBox control is definitely not a
container control.

The use of child controls in non-container controls would be more for
compositing operations (though the lines are blurry even there, as the
UserControl is advertised as much as a way to create a single new control
that's a composite of other controls as it is for acting as a container
for a group of otherwise unrelated controls). Since all controls can have
children controls, the fact that you can add children to a control doesn't
in any way imply it's suitable for acting as a container.

Pete
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I could NOT resize the axis title but excel allows me to resize gr =?Utf-8?B?SXdhbiBTZXRpeW9ubyBLbw==?= Microsoft Excel Charting 4 6th Jun 2006 04:46 AM
Auto resize and position controls upon form's Resize even helpful sql Microsoft Dot NET 4 31st Mar 2006 01:45 AM
RESIZE PROPERTY: is it possible to resize "up" and "to the left"? Myles Microsoft Excel Programming 1 22nd Mar 2006 05:57 AM
I could NOT resize the axis title but excel allows me to resize gr =?Utf-8?B?SXdhbiBTZXRpeW9ubyBLbw==?= Microsoft Excel Charting 0 15th Mar 2006 11:34 AM
Riddle me this: Mdi FormBorderStyle.none code resize vs. border resize Bob Microsoft Dot NET Framework Forms 0 9th Aug 2004 03:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:33 AM.