473,830 Members | 2,105 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 3549
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
4122
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
2373
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
3492
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
6391
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
3478
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
3365
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?
3
2321
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
4293
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
3685
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
9642
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
10202
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9313
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7745
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5617
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
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
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
3958
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.