• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Centering mid child form Problem.

I have an vb 6 project with a mdi form and several mdi child forms. In the load event of the mdi child form
I do the coding such as:

me. width = 6000
me. height = 1000

call CenterForm (this function center the mdi child form against its mdi form).

The problem is sometimes it works fine. But sometime strange things happened when I call it several times for example:

First call, it works fine and then I close the form.
Second call, the top of the form is lower then the first call and so on for the next call.

What I should do in coding to my problem from showing the form till closing the form ?

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 4
  • 4
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Make sure the StartUpPosition() property of your MdiChild form is set to "0 - Manual".
0
 
emi_sastraAuthor Commented:
I have already done so for :

the MDI FORM
StartUpPosition() = "3 - Windows default".
WindowsStata() = "2 - Maximized".

the MDI CHILD FORM:
StartUpPosition() = "0 - Manual".
WindowsStata() = "0 - Normal".

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Can you show us some code where you display the MdiChild forms then?

And also the CenterForm() method.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
emi_sastraAuthor Commented:
At MDI FORM

Private Sub mnu_Master_Curreny_Click()
    frmTMCURCY.show
End Sub

At MID CHILD FORM:

Private Sub Form_Load()
   
    Me.Height = 10590
    Me.Width = 14835
   
    CenterWindows Me    
   
End Sub


MODULE

Public Sub CenterWindows(frmSPForm As Object, _
                         Optional blnHorizontalOnly As Boolean, _
                         Optional blnVerticalOnly As Boolean)
                         
    If blnHorizontalOnly Then
       frmSPForm.Left = (Screen.Width - frmSPForm.Width) / 2
       Exit Sub
    End If
   
    If blnVerticalOnly Then
       frmSPForm.Top = (Screen.Height - frmSPForm.Height - 1000) / 2
       Exit Sub
    End If
   
    frmSPForm.Left = (Screen.Width - frmSPForm.Width) / 2
    frmSPForm.Top = (Screen.Height - frmSPForm.Height - 1000) / 2
   
End Sub
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I'm unable to reproduce the symptoms in a simple project using the information you have given.

Can you upload the project (or a smaller project with these symptoms) so we can try it out?
http://www.ee-stuff.com
0
 
emi_sastraAuthor Commented:
I think it is useless to give the project since it happened occasionally, not every time.

May be you could give me a suggestion.

When to put the :

Me.Height = 10590
    Me.Width = 14835
   
    CenterWindows Me    
0
 
emi_sastraAuthor Commented:
Sorry, haven't finished yet.

I think it is useless to give the project since it happened occasionally, not every time.

May be you could give me a suggestion.

When to put (in what event) the centering call:

   Me.Height = 10590  
    Me.Width = 14835
   
    CenterWindows Me    

    Is me.height  and me.width is needed or we don't need it?

Thank you.       
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The CenterWindows() call should be in the Form_Load() event.

Whether or not the Height/Width code is needed depends on what the size of your form was at design-time.  If it is already at this size then there is no need to do it at run-time as well.

The form resizing code, if needed, should be in the Load() event as well.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now