Mybase.resize being repeatedly called...

  • Thread starter Thread starter Blarney
  • Start date Start date
B

Blarney

Hi all,

I am having a problem with the mybase.resize handler in my program. I
am using the "standard" screen rotation code to handle portrait and
landscape mode.

Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize
If (Screen.PrimaryScreen.Bounds.Width >
Screen.PrimaryScreen.Bounds.Height) Then
Landscape()
Else
portrait()
End If
End Sub

Pretty simple huh? Anyway, I have been wrestling with this for several
days. I normally get a native exception error if I have the same
if/then statement in my form.load handler and the form.resize handler.
So I set a trap and found the following:

1. mybase.resize is being called 2 times while the program loads
2. If I minimize the app and bring it back to the front, mybase.resize
is called

What this results in is the portrait (or landscape) form builder to be
called repeatedly, painting the forms on each other. Which is
obviously slow - plus causes buttons not to work, etc.

Does anyone know what's causing this and how I can work around the
issue?

Thanks!
 
Hi,

I would have to see the landscape and portrait procedure to be sure,
but I think they are resizing the form which will cause the resize event
to fire again. Maybe try something like this.

Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize

Static bRanAlready as Boolean = false

'only run once

If bRanAlready then return

If (Screen.PrimaryScreen.Bounds.Width >
Screen.PrimaryScreen.Bounds.Height) Then
Landscape()
Else
portrait()
End If
bRanAlready = true
End Sub

Ken
--------------------
 
Thank you. The code above does prevent it from resizing more than
once. But it prevents rotation resizing.

What might I look for in the landscape and portrait proceedures that
would be forcing the resize?
 
Hi,

Everytime you change the forms dimensions the resize event will fire.
Try something like this instead.


Static bRanAlready as Boolean = false

'only run every other time

If bRanAlready then
bRanAready = false
return
End if

If (Screen.PrimaryScreen.Bounds.Width >
Screen.PrimaryScreen.Bounds.Height) Then
Landscape()
Else
portrait()
End If
bRanAlready = true


Ken
------------------
 
Back
Top