Windows フォームの場所を異なる速度でスムーズにアニメーション化する方法は?
しかし、何らかの理由で、私の this.Invalidate() 呼び出しは OnPaint イベントを起動しません。これを可能にするためにフォームに必要な構成はありますか?
編集:
独自のメッセージ ループを使用してバックグラウンド ワーカーで実行されるため、スレッド化が必要です。コードは次のとおりです。
public class PopupWorker
{
public event PopupRelocateEventHandler RelocateEvent;
private BackgroundWorker worker;
private MyPopup popupForm;
public PopupWorker()
{
worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
popupForm = PopupCreator.CreatePopup("Title", "BodyText");
this.RelocateEvent += popupForm.OnRelocate;
popupForm.CustomShow();
Application.Run();
}
public void Show()
{
worker.RunWorkerAsync();
}
public void PopupRelocate(object sender, Point newLocation)
{
if (popupForm.InvokeRequired)
popupForm.Invoke(new PopupRelocateEventHandler(PopupRelocate), new object[] {sender, newLocation});
else
RelocateEvent(this, newLocation);
}
}
形 :
public void OnRelocate(object sender, Point newLocation)
{
targetLocation = newLocation;
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (Location.Y != targetLocation.Y)
{
Location = new Point(Location.X, Location.Y + 10);
if (Location.Y > targetLocation.Y)
Location = targetLocation;
this.Invalidate();
}
}