애니메이션 양식 vb.net에서 크기를 조정합니다
문제
데스크탑 창의 오른쪽 하단에있는 작업 표시 줄/시스템 트레이 위에 약간 위치한 양식이 있습니다. 일종의 팝업 알림과 같습니다. 알림 자체는 멋지게 보이지만, 양식을 크기로 만드는 버튼이있어 화면의 오른쪽 하단 모서리에 비해 위치를 유지하면서 5px의 크기를 5px 단위로 애니메이션합니다.
이것의 문제는 그것이 매우 매끄럽게 보이지 않는다는 것입니다. 조정 나 왼쪽에서 크기를 조정하여 양식을 왼쪽으로 이동해야합니다. 나 보상하기 위해. Me.SetBounds는 어쨌든 해당 속성을 설정하는 래퍼 인 것 같습니다.
양식을 부드럽게 (또는 적어도 나타나는) 양식의 왼쪽에서 바깥쪽으로 크기를 조정하기 위해 할 수있는 일이 있습니까?
해결책
ETA: You can actually do this using SetBounds
, as SetBounds
will delegate to SetBoundsCore
which, in turn will invoke SetWindowPos
. So SetBounds
will internally really set all bounds at once and the window manager will redraw the window only after all properties are set.
Another option would be to import the MoveWindow
function and use that instead. It produces a smooth animation here, as it can set size and position simultaneously before telling the window manager to redraw the window.
My test code looked like this (converted from C# via IL to VB with help from Reflector):
Private button1 As Button
Private components As IContainer = Nothing
Private tm As Timer = New Timer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
MyBase.Left = (Screen.PrimaryScreen.WorkingArea.Width - MyBase.Width)
MyBase.Top = (Screen.PrimaryScreen.WorkingArea.Height - MyBase.Height)
Me.tm.Enabled = False
Me.tm.Interval = 20
AddHandler Me.tm.Tick, Function
If (MyBase.Width < 500) Then
Form1.MoveWindow(MyBase.Handle, (MyBase.Left - 5), (MyBase.Top - 5), (MyBase.Width + 5), (MyBase.Height + 5), True)
Else
Me.tm.Enabled = False
End If
End Function
End Sub
<DllImport("user32.dll", SetLastError:=True)> _
Friend Shared Function MoveWindow(ByVal hWnd As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
End Function
다른 팁
나는 이것을 시도한 적이 없지만 양식의 DoubleBuffer 속성을 True로 설정하려고 시도 했습니까? 이것은 그림을 부드럽게해야합니다.
픽셀 단계를 1-2로 줄이려면 5px가 크기를 조정하는 것이 많을 것 같습니다. 이것이 어떻게 고르지 않은 것처럼 보일 수 있는지 알 수 있습니다.