|
-
May 18th, 2003, 03:12 PM
#1
Thread Starter
Lively Member
form resize [resolved]
i have a picbox that i use to draw a graph. dock is set to fill so it will consume the entire graph. but, the graph is scaled and becomes stretched when the user resizes one border of the form. i want the form to always be a square shape, so the height and width are always the same.
i use this code right now, but it gives me a nice little infinite loop:
VB Code:
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
If Me.Width > Me.Height Then
Me.Height = Me.Width
Else
Me.Width = Me.Height
End If
End Sub
any suggestions?
Last edited by joeframbach; May 20th, 2003 at 06:57 PM.
if you choose not to decide you still have made a choice!
RUSH rocks!
-
May 18th, 2003, 05:28 PM
#2
Fanatic Member
Strange, on my machine it doesn't infinitely loop (although it looks to me like it ought to). Why don't you try:
VB Code:
Private Sub Form1_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Resize
If Me.Width <> Me.Height Then
If Me.Width > Me.Height Then
Me.Height = Me.Width
Else
Me.Width = Me.Height
End If
End If
End Sub
This should reduce the number of times the event fires (avoid adjusting width/height if they are already equal)
-
May 18th, 2003, 06:47 PM
#3
Thread Starter
Lively Member
wow. thanks. that was really obvious. 
but im not gonna put [resolved] up there cuz it still flickers
Last edited by joeframbach; May 18th, 2003 at 06:59 PM.
if you choose not to decide you still have made a choice!
RUSH rocks!
-
May 18th, 2003, 07:13 PM
#4
PowerPoster
It is going to flicker because while the user is resizing your form while you are adjusting it also, making it fight back and forth drawing and redrawing the form.
Here is one way to stop that, but you don't get the effect visually:
VB Code:
Dim formResized As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
formResized = False
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
formResized = True
End Sub
Private Sub Form1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseEnter
If formResized = True Then
MessageBox.Show("Form was resized")
Me.Width = Me.Height
formResized = False
End If
End Sub
Last edited by hellswraith; May 18th, 2003 at 07:28 PM.
-
May 18th, 2003, 07:51 PM
#5
Thread Starter
Lively Member
works great! but there has to be a faster way...
if you choose not to decide you still have made a choice!
RUSH rocks!
-
May 19th, 2003, 03:41 AM
#6
Frenzied Member
If you dont want Hellswraith code then the other code will make flicker unless you change your display settings in windows. If you are using windows XP then go to Display Setting, Choose Appearance>Effects and remove the tick where it says: 'Show window contents while dragging'
There should be somthing similar for other windows too.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|