Flashing when switching mdi forms


S

Simon Verona

I have a parent form which contains a toolbar. The toolbar controls the
loading and switching to of MDI child forms.

The code for the toolbar click event and one of the subroutines that loads
and shows a child form is:

Private Sub tbMenu_ButtonClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tbMenu.ButtonClick
Dim btn As System.Windows.Forms.ToolBarButton
For Each btn In Me.tbMenu.Buttons
If Me.Tag = e.Button.Tag Then
btn.Pushed = True
Else
btn.Pushed = False
End If
Next
Select Case e.Button.Tag
Case "0"
AccountEnquiry()
Case "1"
PostInvoice()
Case "99"
Me.Close()
End Select
End Sub
Private Sub AccountEnquiry()
' Account Enuiry
Static frm As New frmPurchaseLedgerAccount
Try
If IsNothing(frm) Then frm = New frmPurchaseLedgerAccount
With frm
..SuspendLayout()
..MdiParent = Me
..WindowState = Windows.Forms.FormWindowState.Maximized
..BringToFront()
..Show()
..ResumeLayout()
End With
Catch
frm = Nothing
AccountEnquiry()
End Try
End Sub


This works fine when the toolbar button is first clicked. The form just
loads and displays.

However, if you then click to another child form and then click back, you
can see the form display and then expand to maximised within the parent form
which flickers and is annoying. I tried inserting the suspendlayout and
resume layouts to see if that helps but it doesn't. Can anybody suggest a
way to stop the flickering?

Thanks in advance
Simon
--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011
 
Ad

Advertisements

T

tommaso.gastaldi

Hi Simon, I am clear what you mean. Why do you not post the lines (and
only the lines) that show your problem, so that we can replicate the
problem and suggest a solution?

It may just be a matter of use activate() instead of bring to front...
(?)

-tom


Simon Verona ha scritto:
 
S

Simon Verona

Hi Simon, I am clear what you mean. Why do you not post the lines (and
only the lines) that show your problem, so that we can replicate the
problem and suggest a solution?

It may just be a matter of use activate() instead of bring to front...
(?)

-tom


Simon Verona ha scritto:

Ok.

It's hard to tell exactly which line causes the problem.

What I'm trying to do is manage MDI forms in code using a toolstrip with
buttons on.

Each time a button on the toolstrip is clicked, the mdi child form for that
button will be created is it doesn't exist and then maximised to fill the
parent mdi form space.

The code I use to instantiate the child form and then display it is :

Private Sub AccountEnquiry()
' Account Enuiry
Static frm As New frmPurchaseLedgerAccount
Try
If IsNothing(frm) Then frm = New frmPurchaseLedgerAccount
With frm
.SuspendLayout()
.MdiParent = Me ' Makes sure the child form is a mdi child
.WindowState = Windows.Forms.FormWindowState.Maximized ' this
maximises it to fill the window
.BringToFront() ' This makes sure it is the front mdi child
.Show() ' Shows the form
.ResumeLayout()
End With
Catch
' It hits here if the child form has been previously displayed and then
closed - it's then disposed so just needs setting to nothing and then
redisplaying
frm = Nothing
AccountEnquiry()
End Try
End Sub

On first instantiation the form just "shows" - already maximised in the
parent.

However, if the form already is instantiated and the user is simply
switching back to it, then the form will display in "normal" size (ie not
maximised) and will then "expand" to fill the window. This gives a
noticeable and annoying flickering.

Does that clarify?

Regards
Simon
 
Ad

Advertisements

S

Simon Verona

Simon Verona said:
Ok.

It's hard to tell exactly which line causes the problem.

What I'm trying to do is manage MDI forms in code using a toolstrip with
buttons on.

Each time a button on the toolstrip is clicked, the mdi child form for
that button will be created is it doesn't exist and then maximised to fill
the parent mdi form space.

The code I use to instantiate the child form and then display it is :

Private Sub AccountEnquiry()
' Account Enuiry
Static frm As New frmPurchaseLedgerAccount
Try
If IsNothing(frm) Then frm = New frmPurchaseLedgerAccount
With frm
.SuspendLayout()
.MdiParent = Me ' Makes sure the child form is a mdi child
.WindowState = Windows.Forms.FormWindowState.Maximized ' this
maximises it to fill the window
.BringToFront() ' This makes sure it is the front mdi child
.Show() ' Shows the form
.ResumeLayout()
End With
Catch
' It hits here if the child form has been previously displayed and then
closed - it's then disposed so just needs setting to nothing and then
redisplaying
frm = Nothing
AccountEnquiry()
End Try
End Sub

On first instantiation the form just "shows" - already maximised in the
parent.

However, if the form already is instantiated and the user is simply
switching back to it, then the form will display in "normal" size (ie not
maximised) and will then "expand" to fill the window. This gives a
noticeable and annoying flickering.

Does that clarify?

Regards
Simon
Typical

A eureka moment just after I post !

If you put a frm.hide statement before the maximise statement in the code,
it then works with no flickering.

Regards
Simon

--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top