Solved

proportional resizing a window in vb.net

Posted on 2014-01-17
17
3,590 Views
Last Modified: 2014-08-10
Experts,

I am trying to allow users of a vb.net 2013 app to resize a window, runtime.
In past Infragistics had a 'resizer' object for VB6, that could be dropped on window, allowing user to drag bottom right corner of window, and all objects proportionally resized with window.

VB.net 2013 has the "containerControl class", but I cant find sample code.
A third party object would also be acceptable, if simpler and works well.

Purpose is to Accommodate  different monitor sizes.

Any suggestions appreciated !

-Larry
0
Comment
Question by:Larry Biederman
  • 7
  • 5
  • 3
  • +1
17 Comments
 
LVL 40
ID: 39790259
Resizing is built into the Windows Forms. You control it through the Anchor property of each individual control.

You use it of fix the distance of some of the borders of the control with the equivalent border of the screen.

The default if Top-Left, meaning that the distance between the top of the control and the top of the control, as well as the distance between the left of the control and the left of the form does not change. The control does stay put in relation to the top and the left. It does not move when you enlarge or reduce the form.

If you set the Anchor to Bottom-Right, it stays put the lower right corner of the form and follows it when you enlarge the form.

Left-Rigt gives you a Control that enlarge horizontally, but not vertically. Top-Bottom is the reverse.

If you set all the 4 anchors, the control always keeps the same margins all around, so it enlarges as the form does.

If you set only the Right anchor, the control will follow the right border when you enlarge, but keeps its relative position vertically. If it's 1/3 down, it will stay 1/3 down relative to the new height.

And so on.

On a complex form, controls might easily overlap each other when resizing. You can control that by putting the controls into Panel controls or other containers. The Anchor is then relative to the container instead of relative to the form.

The MaximumSize and MinimumSize of the form can be set to prevent the user from overdoing the resizing and render the form useless.
0
 
LVL 28

Assisted Solution

by:Ark
Ark earned 200 total points
ID: 39791752
Just my 2 cents: to resize fonts like VB6 'resizer's'
Public Class Form1
    Private lastSize As Size

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lastSize = Me.Size
    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Dim newSize = Me.Size
        Dim ratio = newSize.Height / lastSize.Height
        ResizeFonts(Me, ratio)
        lastSize = newSize
    End Sub

    Private Sub ResizeFonts(ByVal container As Control, ByVal ratio As Double)
        For Each c As Control In container.Controls
            If c.HasChildren Then ResizeFonts(c, ratio)
            Try
                Dim fnt = c.Font
                If Not fnt Is Nothing Then
                    Dim newFontSize As Single = fnt.Size * ratio
                    c.Font = New Font(fnt.FontFamily, newFontSize, fnt.Style)
                End If
            Catch ex As Exception

            End Try
        Next
    End Sub
End Class

Open in new window

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 300 total points
ID: 39791818
Resizing the fonts on the whole form is not a very good thing to do.

This might be OK if all the controls are resizing, but in my experience, this is not something that happens often. What is most usual is to have some controls that resize and others that don't.

On a form that shows a grid for instance, with maybe a few buttons under it for controls, you get a very bad effect if you resize both the grid and the buttons. Usually the buttons will stay the same size. Seeing text that changes size on buttons that don't is annoying.

TextBoxes that are meant to hold only one line of text will usually resize horizontally but not vertically. Enlarging the fonts might make them useless.

Changing the font of some controls such as menus and tabs on tab controls give awful results. The user sees the same font in all its applications, and suddenly, because he change the size of a  form, he ends up with controls that do not look right.

The main reason to enlarge a form is usually so that you can show more information, such as more lines in a Multiline TextBox, more rows and columns in a grid. If you change the size of the font as the form enlarge, you completely lose the usefulness of the whole thing.

Many programmers think that they should reduce the font when the form is reduced, otherwise the text won't fit anymore. That may make it too small to be readable. The best thing is usually to leave enough space around the text so that some amount or reduction is permitted, and use the MinimumSize property of the controls or the form to make sure that the thing is not overdone.

An option for the user to manually change the font if desired is, as far as I am concerned, a far better option than doing it automatically.

Look at all the good software around. Look at Office. They almost all have an option to zoom in or out, but they do not resize the font when you resize the application.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 28

Expert Comment

by:Ark
ID: 39791824
Hi James. I'm totally agree, but.
Did you see any VB6 resizer (including Infragistics one)? All them resized fonts as well. I just added those 2 cents in case TS need this future too.
0
 

Author Comment

by:Larry Biederman
ID: 39793176
Art and James,

I haven't had success with the anchors. Using a sizable border on forms, it still does not perform well.

1- Yes the resizer was part of Data Widgets 3.1 from infragistics (which was Sheridan befre Infragistics took over).

2- What about the containercontrol class methods built into vb.net?
http://msdn.microsoft.com/en-us/library/system.windows.forms.containercontrol(v=vs.110).aspx

Thanks fellows,
Larry
0
 
LVL 28

Assisted Solution

by:Ark
Ark earned 200 total points
ID: 39793218
Just set anchor for all controls to Top+Left+Bottom+Right (note: set autosize property to false for labels)
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 300 total points
ID: 39793230
Although it might seem strange for somedy who comes from VB6, in .NET a Form is a Control. Digging further, it is a little more, it is a container control. Click on More... in the link that you sent us, and you will see that Form sits under under ContainerControl. This shows inheritance between a ContainerControl and a Form. So everything a container control does, a Form does.

The Anchor property might not be intuitive at first, until you have grasped the way its work, which is different than what the Data Widgets were doing.

Send a screenshot of what you get after resizing a form on which you used Anchor on some of the controls, and point out the problems that you get. We might be able to explain what you should do to make Anchor work to your needs.
0
 

Author Comment

by:Larry Biederman
ID: 39799927
Fellows,
Thanks for the new, expert info.  I will try this soon.
I Will be away a few days.

Will test and award points in few days.

Thanks so much, Larry
0
 

Author Comment

by:Larry Biederman
ID: 39831167
Experts,
I'm Back at work.  Will check this out this week.

Thanks for patience, Lbiederman
0
 

Author Comment

by:Larry Biederman
ID: 39833803
Ive tried anchors in all four corners in this app.
Its in VB.net 2013.
I put anchors on four corners of the panel on the form.  Form is resizable.
Try it.  Nothing resizes at all.

Experts Exchange disallows the upload, So I have it on this link:

test1.zip (466.6 KB) =>

https://files.secureserver.net/0s91Kxaq0i9mdw

Ideas??
Thanks, LBiederman
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 300 total points
ID: 39834491
Your Panel does resize. Just give it a BackColor and you will see.

However, you did not set the Anchor on the included controls, so they do not follow the Panel.

With many controls in many columns as what you have however, setting everything right will call for a lot of trial and error. I unfortunately do not have the time to "play" with your Form, but from past experience, stuff like that usually requires a Panel for each column, with possibly some mix of the Dock and the Anchor property.

And it can be a lot of work before you end up having something that works right. Why do you think that software such as Excel does not have an option to automatically enlarge the columns when you enlarge the main window?

Personally, I would drop the idea of making that window sizable.

As it is, you Form will fit almost any monitor in used today if you diminish the width just a bit to 1028. And if it is to be used in-house, you might ask around, and maybe you can go for bigger than that. If it is not sufficient to display all the data, you still have room to enlarge the TextBoxes. If they do not have to be in a very specific order, move them around so that the larger ones are all in the same column, so the 2 other columns can be set narrower.
0
 

Author Comment

by:Larry Biederman
ID: 39834533
Thanks JamesBurger,

That was just a demo form I created for you, as Experts-Exchange blocks many files in VB.net projects.

I know excel etc. do not resize.  BUT.. IE browser does!!!
Try this:
Minimize IE. Then expand it to half screen.  Now drag bottom right corner.
It minimizes about 20% then portions begin  to hide.
If you resize bottom center up, it does not resize.

How is that done?
If I could do same as Internet explorer does, It would suffice.

Can you look at it, and advise?
Thanks so much Jim,

Larry
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 300 total points
ID: 39834856
It's not IE that does it, it's the HTML in the page. Microsoft used something that works a bit like that in the new Windows 8 interface.

But the standard Windows has nothing built in. So Microsoft added the Anchor and Dock properties to .NET controls to enable us to resize forms. But since it has not been implemented the same way as in HTML and Windows 8, you cannot expect to have the same behaviour.

And as for HTML and for Windows 8, it's a lot of trial and error.

The Anchor works within the container in which you put a Control.

When  you put a Panel in a Form and Anchor it, it resizes following its container, the Form.

When you put a Control on a Panel and Anchor it, it resizes following its container, the Panel.

So you should Anchor both the Panel to the Form, and the Controls to the Panel. If you do not set the Anchor on the controls, they won't resize as the Panel follows the form. This is what happened in your sample.
0
 

Author Closing Comment

by:Larry Biederman
ID: 39840494
Lots of good information, just no good solution exists out there, apparently.

Your education and code samples much appreciated !!

LBiederman
0
 

Expert Comment

by:ckelsoe
ID: 40251396
http://www.lyoung.com/ does what you need.
0
 

Author Comment

by:Larry Biederman
ID: 40252271
Thanks JamesBurger,
If tried this before, but you have given al little more info.
Will play with it this week.

Thanks,
LarryBiederman
0
 

Expert Comment

by:ckelsoe
ID: 40252275
i have one small app that needs to display fair auction bid results on  multiple tvs and monitors . this control scales everything to maximum size of tvs where i to not have to worry about resolutions.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question