Solved

How to avoid form flashing when resized

Posted on 2004-04-16
4
190 Views
Last Modified: 2013-12-25
Hello,
I want a form to always keep the same Width/Height ratio when it is resized by the end-user, for example twice as wide as height.

Here is what I have written :
Private Sub Form_Resize()
    Dim H&, W&
    Static OldWidth&, OldHeight&, DoNoChange As Boolean
    'DoNoChange is used to avoid recurse process called from inside the Form_Load event
    If DoNoChange Then Exit Sub
    W = Width: H = Height
    If W <> OldWidth Then
        H = W /2: If Height <> H Then DoNoChange = True: Height = H: DoNoChange = False
    ElseIf H <> OldHeight Then
        W = H *2:  If Width <> W Then DoNoChange = True: Width = W: DoNoChange = False
        End If
    End If
    OldWidth = Width
    OldHeight = Height
End Sub

1> It works well when the form is resized by dragging its left border but not well when one drags the bottom border
2> The form "flashes" as long as the dragging process is not completed
How to specify that the resizing is still in process (telling the form "do not change the other dimension) or completed ("Do change the other dimension") ?

Thank you very much.
Philippe
Philippe.
0
Comment
Question by:MSelect
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 10844636
You cannot accomplish that without subclassing the form and trapping events for the window.

You could modify Ark's code here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_20413753.html

Regards,

Idle_Mind
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 10844686
But you could cheat with a Timer control.

Private Sub Form_Resize()
Timer1.Enabled = True
Timer1.Interval = 500 'Adjust interval to suit
End Sub

Private Sub Timer1_Timer()
    Dim H&, W&
    Static OldWidth&, OldHeight&, DoNoChange As Boolean
    'DoNoChange is used to avoid recurse process called from inside the Form_Load event
    If DoNoChange Then Exit Sub
    W = Width: H = Height
    If W <> OldWidth Then
        H = W / 2: If Height <> H Then DoNoChange = True: Height = H: DoNoChange = False
    ElseIf H <> OldHeight Then
        W = H * 2: If Width <> W Then DoNoChange = True: Width = W: DoNoChange = False
        'End If
    End If
    OldWidth = Width
    OldHeight = Height
    Debug.Print Now
    Timer1.Enabled = False
End Sub


0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 10844705
Also take a look a this post: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_10121021.html

It discusses the events you need to trap to determine when the form has stopped being resized.

Idle_Mind
0
 

Author Comment

by:MSelect
ID: 10849445
I well thought that a solution was in subclassing the window  ... but
1> I didn't know which WM_ messages I had to use
2> I hoped that there would be a "pure" VB solution

Thank you very much for your effort ...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

756 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