Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to avoid form flashing when resized

Posted on 2004-04-16
4
Medium Priority
?
196 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 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 1000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

885 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