简体   繁体   中英

Managing modal forms location

I've got a "Loading" form which I display as a modal form when doing lengthy processes. I'm using the below to keep the form centred within the child form performing the process. However, when minimising\\maximising the "Loading" form appears before the parent making it look a little unprofessional.

Anything I can do about that (Delay it appearing or attaching it in a different way)?

Private _childForm As FormBusy
Private Const NIM_DELETE = &H2
Private Sub SetChildFormPosition()
    If _childForm Is Nothing Then
        Return
    End If
    Dim newLocation As New Point()
    newLocation.X = Me.Location.X + ((Me.Width - _childForm.Width) \ 2)
    newLocation.Y = Me.Location.Y + ((Me.Height - _childForm.Height) \ 2)
    _childForm.Location = newLocation
End Sub

Private Sub ParentForm_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
    SetChildFormPosition()
End Sub

When I tried this with empty forms, the two forms appeared at once. It's possible that the delay is in processing Windows messages. You might try putting Application.DoEvents() inside the loop in the parent form to process messages faster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM