Solved

How to avoid form flashing when resized

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 code to programmatically convert pdf to excel 21 92
VBA error replacing data 6 40
VBS file using code from 2nd file (txt or vbs) 4 36
Send outlook email from VBS Script 2 30
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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

777 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