Solved

Is there a quick way to resize forms and controls?!

Posted on 2010-08-24
6
739 Views
Last Modified: 2012-06-21
We have an big software made in WinForm VB 2008 designed with 1280X1024 forms. Previous version of our software worked on 1024X768 screens. Now, we are upgrading those clients with the newer version, but the touch-screen (it's an embedded industrial computer) does not support 1280X1024 resolution (it's something we all missed before giving the go-ahead for the upgrade). So, we have to resize all the forms and controls, and spacing between each controls, to fit the 1280 interface into 1024.

We decided to make a new version and copy/paste all control and code and manually resize the whole things (there are a lot of forms and controls...) which will take very much time. Ideally, we should have a single version that support both resolutions, as maintenance of both versions will quickly become a nightmare.

Anyone have an idea of how we could automatically resize forms and controls, depending of the resolution? Getting the best resolution of the graphic card is not a problem, it's the resizing of forms and controls that give us headache...

thanks for your time and help
0
Comment
Question by:Dominic34
6 Comments
 
LVL 20

Accepted Solution

by:
alainbryden earned 500 total points
ID: 33510375
I've always made my controls re-sizable to any resolution simply by implementing the form_resize event. Instead of using fixed positions, calculate them in this event. Don't assign Top, Width, Height, etc constant values - use a series of formula to calculate how much space is available, and what their respective positions should be relative to each other.

It will take a little effort this first time, since you're overhauling the UI layout, but after that you'll never have to worry about resolution problems again.

I've attached an example.

--
Alain
Const ListboxPadding = 1
Const ButtonPadding = 3
Const MinHeight = 100
Const MinWidth = 520

Private Sub UserForm_Resize()
    With ButtonSearchBasic
        .Top = Me.InsideHeight - ButtonPadding * 2 - .Height
    End With
    With ButtonSearch1
        .Top = Me.InsideHeight - ButtonPadding * 2 - .Height
    End With
    With ButtonSearch2
        .Top = Me.InsideHeight - ButtonPadding * 2 - .Height
    End With
    With ButtonExit
        .Top = Me.InsideHeight - ButtonPadding - .Height
        .Left = Me.InsideWidth - ButtonPadding - .Width
    End With
    With ButtonFillOverwrite
        .Top = Me.InsideHeight - ButtonPadding - .Height
        .Left = Me.InsideWidth - ButtonPadding * 4 - .Width - ButtonExit.Width
    End With
    With ButtonFillEmpty
        .Top = Me.InsideHeight - ButtonPadding - .Height
        .Left = Me.InsideWidth - ButtonPadding * 6 - .Width - ButtonFillOverwrite.Width - ButtonExit.Width
    End With
    With ResizeGrab
        .Left = Me.InsideWidth - .Width
        .Top = Me.InsideHeight - .Height
    End With
    With ResultList
        .Top = ListboxPadding
        .Left = ListboxPadding
        .Height = Me.InsideHeight - 2 * ButtonPadding - ButtonExit.Height - .Top
        .Width = Me.InsideWidth - .Left - ListboxPadding
    End With
End Sub

Open in new window

0
 
LVL 22

Expert Comment

by:plusone3055
ID: 33510404
There really isnt much that you can do. Thats one of those design flaws that happens in developement. Its always wiser to make the sizes universal and allow the user to size the screen themselves once the executable is launched. this is why we have scrolling bars and form controls set so the user can size the application themselves :(

Take this as a lesson learend and call up the original developers and make them do the transition. Save both copies for future code changes.


Heres some more light readon on the subject

http://www.devx.com/DevX/10MinuteSolution/20412



0
 
LVL 20

Expert Comment

by:alainbryden
ID: 33510413
This is just a separate thought - but if you want something real quick, you should give this a shot:

Detect the resolution (available width and height), then try looping over all controls on the form and multiplying their top, left, width and height by a constant ratio equal to the expected resolution over the actual resolution.

I think I did this once, so I'm going to try and track down the code. Hang tight.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:gozoliet
ID: 33510482
This article was helpful for me. Docking controls, and only resizing the panels. Kinda like a flowLayout.

http://www.codeproject.com/KB/vb/pflvb7.aspx
0
 

Author Comment

by:Dominic34
ID: 33510733
alainbryden, really interesting. What is the Me.InsideHeight variable is your example?
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 33512096
Me refers to the form itself, and InsideHeight refers to the area of the form that controls can occupy (i.e. doesn't include the window title and frame dimensions.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net PaintEventArgs Handling. 10 33
How to Get total minutes between two hours 4 44
VB.NET HttpWebRequest 12 55
Recommendation vb6 to vb.net or others 14 104
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now