Я запускаю программу на VB.net, где мне действительно нужно сделать хорошую анимацию для открытия и закрытия форм.
Сейчас у меня есть родительская форма, которая используется в качестве "фона" дляприложение, пока оно может открывать другие формы внутри.Две формы будут загружены при открытии приложения, и я хочу, чтобы первая сместилась влево в желаемое положение, а вторая - снизу и сместилась в нужное место.
Цель состоит в том, чтобыВот так это выглядит примерно так:
_______________ _______________
| _____ | | _____ ____ |
| | | | | | | | B| |
| | A | | To | | A | |__| |
| |___| | | |___| |
|_____________| |_____________|
Правильно, я пытался сразу загрузить две формы у родителя, затем поместить их в середину экрана и запустить таймер, чтобы каждый тик делалформа смещается влево, а когда она в позиции, другая идет направо.
Вот код, когда родительская форма загружается
Dim WithEvents tmr As New Timer
Private Sub Fr_Parent_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
IsMdiContainer = True
Dim FrTicket As New FrTicket()
FrTicket.MdiParent = Me
FrTicket.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
FrTicket.Show()
Dim FrIdentite As New FrIdentite()
FrIdentite.MdiParent = Me
FrIdentite.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
FrIdentite.Show()
Dim HautEcran As Integer
Dim LargEcran As Integer
LargEcran = CInt(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString())
HautEcran = CInt(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString())
Dim LargFrmSite As Integer = FrIdentite.Width
Dim hautFrmSite As Integer = FrIdentite.Height
FrIdentite.Location = New Point((LargEcran / 2 - LargFrmSite / 2), (HautEcran / 2 - hautFrmSite / 2))
FrTicket.Location = New Point((LargEcran / 2 - LargFrmSite / 2), (HautEcran / 2 - hautFrmSite / 2))
tmr.Start()
End Sub
А затем тот, который используется на отметке
Private Sub tmr_Tick()
Dim HautEcran As Integer
Dim LargEcran As Integer
LargEcran = CInt(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString())
HautEcran = CInt(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString())
Dim LargFrmSite As Integer = FrIdentite.Width
Dim hautFrmSite As Integer = FrIdentite.Height
Dim xIdenLoc As Integer = CInt(LargEcran / 2 - (LargFrmSite * 1.01))
Dim yIdenLoc As Integer = CInt(HautEcran / 2 - hautFrmSite / 2)
Dim xTicketLoc As Integer = CInt(LargEcran / 2 + (LargFrmSite * 1.01) - LargFrmSite)
Dim yTicketLoc As Integer = CInt(HautEcran / 2 - hautFrmSite / 2)
Dim TheLocalisationOfIden As Integer = FrIdentite.Location.X
If TheLocalisationOfIden >= xIdenLoc Then
FrIdentite.Location = New Point(TheLocalisationOfIden - 1, yIdenLoc)
FrTicket.Location = New Point(TheLocalisationOfIden - 1, yTicketLoc)
Else
If FrTicket.Location.X <= xTicketLoc Then
FrTicket.Location = New Point(TheLocalisationOfIden + 1, yTicketLoc)
Else
tmr.Stop()
End If
End If
End Sub
Но на самом деле они появляются при первой локализации (рисунок 1) и ... ничего.
РЕДАКТИРОВАТЬ: Вот последний код Tick.Переменные теперь объявлены перед подпрограммами
Private Sub tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.Tick
TheLocalisationOfIden = TheLocalisationOfIden - 2
TheLocalisationOfIden = TheLocalisationOfTicket + 2
If TheLocalisationOfIden <= xIdenLoc Then
FrIdentite.Location = New Point(TheLocalisationOfIden, yIdenLoc)
Else
If FrTicket.Location.X >= xTicketLoc Then
FrTicket.Location = New Point(TheLocalisationOfTicket, yTicketLoc)
Else
tmr.Stop()
End If
End If
End Sub