Discussion:
resizing a .net windows form controls
(too old to reply)
Mark
2008-08-14 19:36:09 UTC
Permalink
Hi...

Sorry for the newbie questions but I've inherited a .net-written windows
form app with a bunch of controls on it. A request came in to
1) make the form resizable
2) make the select boxes automatically resize with the box.

I found some posts online about adding panels and setting the anchors
"properly", so I've been experimenting but it's just a mess.

I got 2 drop-downs and a button on one panel that doesn't need a whole lot
of resizing. Under that, I have another panel one multi-select box and 6
buttons vertically next to it. Under that, I have another panel with a
multi-select box and 2 buttons. That panel is sometimes shown, sometimes not.

When the form has FormBorderStyle=Sizable, I can resize the form but none of
the controls/panels resize. When the form has AutoSize=true, things start
getting weird. I can pull the grow handle, but it always snaps back to the
original size.

As I've fiddled with Docking and Anchors on the various panels, I've gotten
all kinds of bizarre behavior but nothing approximating a smooth behavior.

What are the tricks I'm missing?

Thanks
Mark
Zhi-Xin Ye [MSFT]
2008-08-15 05:36:14 UTC
Permalink
Dear Mark,

I'm sorry I don't quit understand your question. In your email:

--> "2) make the select boxes automatically resize with the box."

What do you mean of "select boxes" and "box"?

And do you want to rechieve this in designer or at runtime?

I'm looking forward to your reply.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how

we can improve the support we provide to you. Please feel free to let my
manager know what you

think of the level of service provided. You can send feedback directly to
my manager at:

***@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take

approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient

resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump

analysis issues. Issues of this nature are best handled working with a
dedicated Microsoft

Support Engineer by contacting Microsoft Customer Support Services (CSS) at

http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warran
Mark
2008-08-15 14:19:00 UTC
Permalink
Hi...

Thank you for your reply.

I have a form with 3 Panels on it, arranged vertically. The top Panel
contains a button and 2 ComboBoxes. It will always be visible and on top.
The middle Panel contains a ListBox and a number of buttons. This Panel (and
the ListBox) want to automatically resize as the form is extended.

The thing that appears to complicate matters a great deal is that the 3rd
Panel (which also has a ListBox) on the bottom is usually not visible. The
middle Panel has a button to show/hide the bottom Panel. The bottom Panel is
a fixed size, but the problem the form has rendering seems to be with the
visible/not visible.

I had to stumble through all the counter-intuitive things about the form
designer (like setting AutoResize = true actually prevents most things from
being properly resized) before stumbling on something that *kind of works*.

My current approach (which still works less well than IE and html) is that I
have the top Panel Dock = Top, the middle Panel Dock = Fill and the bottom
Panel Dock = Bottom.

This mostly works but has a number of deficiencies. For example, when
resizing the form, it always leaves blank space for the bottom Panel even
when it is not visible. Another deficiency is that when the form is resized
smaller, the bottom Panel does not respect the middle Panel's MinimumSize (in
other words the bottom panel just mashes over the middle pannel).

As I said above, it seems like you guys would be better taking the IE
rendering engine and doing the forms as HTML. IE seems to do much better
with flow and sizing.

Mark
Mick Doherty
2008-08-16 09:23:20 UTC
Permalink
z-order is very important with docking like this.

Bring the main Panel to Front and it should all work exactly as you expect.
--
Mick Doherty
http://dotnetrix.co.uk/nothing.htm
Post by Mark
Hi...
Thank you for your reply.
I have a form with 3 Panels on it, arranged vertically. The top Panel
contains a button and 2 ComboBoxes. It will always be visible and on top.
The middle Panel contains a ListBox and a number of buttons. This Panel (and
the ListBox) want to automatically resize as the form is extended.
The thing that appears to complicate matters a great deal is that the 3rd
Panel (which also has a ListBox) on the bottom is usually not visible.
The
middle Panel has a button to show/hide the bottom Panel. The bottom Panel is
a fixed size, but the problem the form has rendering seems to be with the
visible/not visible.
I had to stumble through all the counter-intuitive things about the form
designer (like setting AutoResize = true actually prevents most things from
being properly resized) before stumbling on something that *kind of works*.
My current approach (which still works less well than IE and html) is that I
have the top Panel Dock = Top, the middle Panel Dock = Fill and the bottom
Panel Dock = Bottom.
This mostly works but has a number of deficiencies. For example, when
resizing the form, it always leaves blank space for the bottom Panel even
when it is not visible. Another deficiency is that when the form is resized
smaller, the bottom Panel does not respect the middle Panel's MinimumSize (in
other words the bottom panel just mashes over the middle pannel).
As I said above, it seems like you guys would be better taking the IE
rendering engine and doing the forms as HTML. IE seems to do much better
with flow and sizing.
Mark
Olaf Rabbachin
2008-08-16 12:34:52 UTC
Permalink
Hi,
Post by Mark
My current approach (which still works less well than IE and html) is that I
have the top Panel Dock = Top, the middle Panel Dock = Fill and the bottom
Panel Dock = Bottom.
I would be using a TableLayoutPanel for stuff like that (seethe Containers
group in the toolbox). You will need to change the TLP so that it contains
3 rows and 1 column. Set its <Dock>-prop to <Fill>. If necessary, adjust
Padding and/or Margin so your panels have some space between them and the
form's outer limits. If all panels should be resized equally, set all rows'
SizeType to 33.33%.
Then set the anchor property for all controls in the panels accordingly.
You *could* also create another TLP for each of the panels, but depending
on the number of controls, the performance of nested TLPs may decrease
quickly.

Cheers,
Olaf
Mark
2008-08-16 17:15:01 UTC
Permalink
Thanks for your suggestions, guys. None of them seemed to work, but thanks.

Fiddling with the z-order made no change whatsoever.

I tried putting all of my existing Panels into a 3-row tableLayoutPanel, and
not only did the flow not work right, the designer was kind enough to snip
all of my event handlers making the buttons useless.

I happened to stumble across something that did work in the end. I set the
Dock = Fill on the middle Panel *after* I hid the bottom Panel and executed
the Layout. For whatever mysterious reason, that seemed to produce the right
behavior.

It's been a long time since I worked with software as counter-intuitive,
self-destructive and productivity-inhibiting as the forms designer, I have to
say.

Thanks
Mark
Olaf Rabbachin
2008-08-18 07:15:54 UTC
Permalink
Hi,
Post by Mark
I tried putting all of my existing Panels into a 3-row tableLayoutPanel, and
not only did the flow not work right, the designer was kind enough to snip
all of my event handlers making the buttons useless.
Cut and Paste actions will remove the Handles-clauses of your events, yes.
The code will remain there though.
Post by Mark
I happened to stumble across something that did work in the end. I set the
Dock = Fill on the middle Panel *after* I hid the bottom Panel and executed
the Layout. For whatever mysterious reason, that seemed to produce the right
behavior.
I noticed that some parts of the docking and anchoring don't work as
expected too. A while back I wanted to save a form's location and size when
it was closed, so next time it opened it would appear just as it was back
then. I did that via property-binding. The result was that location and
size were right, but the anchoring didn't seem to fire. I.e., the controls'
weren't resized according to their anchor properties.
This was in a VS2005-solution and I never checked this with VS2008.
Also, I noticed that, if there is many columns and heavy usage of the
ColumnSpan and RowSpan properties, the TLP will not behave as expected.
Post by Mark
It's been a long time since I worked with software as counter-intuitive,
self-destructive and productivity-inhibiting as the forms designer, I have to
say.
Well, I must say that I very much appreciate the anchoring stuff and the
TLP. Back in the VB days I either coded resizing or used stuff like the
ComponentOne Sizer control. Both were a lot of work.

Re-reading your original posting, I guess that a) you don't need those 3
panels in general, it's rather the need for a couple of controls that might
have to be hidden. Thus, I'd only include those in a panel. If the panel
would then be placed in a TLP whose column/row is set to AutoSize, there is
a chance that sizing would work. If not, I'd simply add/remove the controls
to the form when required.
Also, if the form's size "snaps back" while resizing, check the MiniumSize
and MaximumSize properties.

But whatever might be your problem, if you can't work around unexpected
behaviour using anchors nor a TLP, why not write some code to do the
resizing. The number of controls you mentioned certainly wouldn't make me
look into too many non-code things ...

Cheers,
Olaf
Zhi-Xin Ye [MSFT]
2008-08-18 07:15:29 UTC
Permalink
Dear Mark,

I would recommend you use the SplitContainer control.

The SplitContainer contains two resizable panels on it (you can aslo
specify one of the panels to be fixed), however, the SplitContainer control
is not a control simply combines two panels.

You can take the following steps to have a try with the SplitContainer
control:

1. Add a panel to the form, set its Dock property to Top;
2. Add a SplitContainer control to the form, the Dock property of the
SplitContainer control is set to Fill by default;
3. Change the Orientation property of the SplitContainer to Horizontal;
4. Set the FixedPanel property to Panel2, the Panel2 will behavior as your
bottom panell;
5. Set the Panel2MinSize to the size you need;
6. Set the Panel1MinSize to the size you need, the Panel1 will behavior as
your middle panel;
7. Add some controls to the panels;
8. Resize the form to test the result.

Moreover, to hide the bottom panel, you can call the hide method of the
SplitContainer.Panel2.

For more information about the SplitContainer control, you can refer to
this document:

SplitContainer Class
http://msdn.microsoft.com/en-us/library/system.windows.forms.splitcontainer.
aspx

Should you have any questions, please feel free to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
***@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Loading...