473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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?
Mar 6 '08 #1
3 4278
On Thu, 06 Mar 2008 09:43:26 -0800, <za***@construction-imaging.comwrote:
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

Mar 6 '08 #2
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
Mar 6 '08 #3
On Thu, 06 Mar 2008 10:04:53 -0800, "Peter Duniho"
<Np*********@nnowslpianmk.comwrote:
>On Thu, 06 Mar 2008 09:43:26 -0800, <za***@construction-imaging.comwrote:
>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?
Mar 6 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kevin Myers | last post by:
Hello folks, I am an experienced developer with other languages and applications, but a neophyte when it comes to MS Access forms. Can someone please help get me with a solution for the...
1
by: Kalvin | last post by:
I am using a nested table to control different elements of my layout. The problem I have is that I create the outer table and set the size properties to what I want them to be, then, if I put...
4
by: Rob Richardson | last post by:
Greetings! I have a form with a listview, a menu, and a few text boxes, labels and command buttons. I want to resize the listview when the form is resized to that the widths of the spaces...
8
by: nirdeshonline | last post by:
Hi, I have added a simple listbox in windows form under c# 2.0. It contains a collection of approx 10 strings as list items. Now when i resize the form whole listbox flickers. Please tell me...
11
by: Ajith Menon | last post by:
I have created a windows application in which the form needs to be resized on the MouseMove event. The windows resize function takes a lot of CPU cycles. And as the resize function is called on the...
2
by: Smitty | last post by:
Did a search & found nothing on this. VB6 did a resize on form load according to what I've read. I Resized screen under vista & now the text box doesn't resize to form's clientarea. Code exists...
6
by: Doc John | last post by:
Assuming I have several child Forms open (not maximized) in my MDI Form, when I maximize any of them and then close it, all my other Forms automatically maximize. How come? Is there an easy...
3
by: monadel | last post by:
Hi guys, How do you resize a form in VB. Basically when user drag the form to minimise or maximise, it will resize all the components inside the form. thanks
3
by: zacks | last post by:
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...
1
by: joedalton101 | last post by:
Is there some piece of code that will make subforms resize automatically according to the amount of records displayed? For example my main form just contains artist names. Subform1 contains...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.