473,941 Members | 3,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4296
On Thu, 06 Mar 2008 09:43:26 -0800, <za***@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

Mar 6 '08 #2
On Thu, 06 Mar 2008 12:24:57 -0800, <za***@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
Mar 6 '08 #3
On Thu, 06 Mar 2008 10:04:53 -0800, "Peter Duniho"
<Np*********@nn owslpianmk.comw rote:
>On Thu, 06 Mar 2008 09:43:26 -0800, <za***@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?
Mar 6 '08 #4

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

Similar topics

1
4128
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 following issue: On a form, I have an object (ImgEdit control from MS Imaging) that needs to automatically grow and shrink when a user resizes the form. The object *does not* need to grow and shrink based on the size of the image that is being...
1
2379
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 another table into the first cell, when I resize that nested table, it automatically resizes the other cells also. If I do the same type of thing in Dreamweaver, this doesn't happen. Is there a setting of some sort in ..NET that I can turn off to...
4
3501
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 between the borders of the listview and the borders of the form remain constant. I am finding this to be unexpectedly hard. For one thing, I initialized some values in the form's Load event, and I'm doing the control resizing in the form's Resize...
8
6409
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 any feasible solution, i need to use a checked listbox which also has same flickering problem on resize. Thanks & Regards
11
3490
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 MouseMove, the form is resized around a 30-100 times in one second. This leads to a high CPU utilization and all other application comes to a stand still. The form does not have any controls i.e. buttons, text boxes etc. It is completely...
2
3373
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 under form1.resize_click Works when I resize the form and also when I include a call to resize under form load event Is this due to vs2005, vista or some other querk?
6
5986
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 solution for this? Thanks. VS2005 - Windows Forms
3
2325
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
3555
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 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...
1
3692
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 albums. Some artists have 2 albums, some have 20. It looks stupid to have a subform resized manually and made huge when it is only filled up with records sometimes, depending on who is selected in the main form. Thanks
0
9964
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11529
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11111
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.