Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Automatically Resize Form?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zacks@construction-imaging.com - 06 Mar 2008 17:43 GMT
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?
kimiraikkonen - 06 Mar 2008 17:55 GMT
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
[quoted text clipped - 5 lines]
> 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.
kimiraikkonen - 06 Mar 2008 17:57 GMT
> On Mar 6, 7:43 pm, za...@construction-imaging.com wrote:
>
[quoted text clipped - 20 lines]
>
> Hope this helps.

Note: Of course do this when you need it, so put them in a IF....Then
statment block.
zacks@construction-imaging.com - 06 Mar 2008 20:24 GMT
> On Mar 6, 7:43 pm, za...@construction-imaging.com wrote:
>
[quoted text clipped - 20 lines]
>
> 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();
kimiraikkonen - 06 Mar 2008 20:30 GMT
On Mar 6, 10:24 pm, za...@construction-imaging.com wrote:

> > On Mar 6, 7:43 pm, za...@construction-imaging.com wrote:
>
[quoted text clipped - 32 lines]
>
> - Show quoted text -

So did it work for you?
Peter Duniho - 06 Mar 2008 21:04 GMT
> Not "automatic" but it has the distinct advantage of working.
>
[quoted text clipped - 5 lines]
> 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
Peter Duniho - 06 Mar 2008 18:04 GMT
> 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
[quoted text clipped - 5 lines]
> 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
Joe Cool - 06 Mar 2008 22:55 GMT
>> 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
[quoted text clipped - 14 lines]
>Then as items are added or removed from the control, it will resize  
>appropriately.

What control would be a "proper container control"? Panel?
Peter Duniho - 06 Mar 2008 23:51 GMT
> 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.