Solved

How to avoid form flashing when resized

Posted on 2004-04-16
4
185 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
  • 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

11 Experts available now in Live!

Get 1:1 Help Now