ボタンを押したときにボタンにアニメーションを適用したい。 WPFでは、アニメーションを作成するトリガー付きのStoryboard
を使用できます。次に例を示します。ボタン - C#Windowsフォームのアニメーションされたグロー効果
<Storyboard x:Key="AniOpacityDelay">
<DoubleAnimation
Storyboard.TargetName="background"
Storyboard.TargetProperty="Opacity"
AutoReverse="True"
To="0.65"
Duration="0:0:0.2"/>
</Storyboard>
と:
<ColorAnimationUsingKeyFrames
Storyboard.TargetName="Itemcont"
Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="#EEEEEE"/>
</ColorAnimationUsingKeyFrames>
WindowsフォームはStoryboard
およびトリガーを持っていません。 Windowsフォームで滑らかなアニメーションを作成するには?ここで
は、Windowsフォームのための私のコードです:
void DelayTime()
{
timer = new Timer();
timer.Interval = (int)System.TimeSpan.FromSeconds(this.DelayTime).TotalMilliseconds;
timer.Tick += (s, es) =>
{
this.mouseover = false;
this.Cursor = Cursors.Hand;
this.Enabled = true;
};
timer.Start();
}
protected override void OnMouseDown(MouseEventArgs mevent)
{
base.OnMouseDown(mevent);
mouseover = true;
this.Enabled = false;
DelayTime();
}
protected override void OnPaint(PaintEventArgs e)
{
Color bg = this._Background;
bg = mouseover ? this._HoverColor : this._Background;
e.Graphics.FillRectangle(new SolidBrush(bg), this.ClientRectangle);
}
WinFormsのことで本当に良いではありません。 – Maarten
無駄な喜びのためにWPFと一緒に滞在してください。 – TaW
ええ、WPFは良いです。しかし、問題は私が良いコンピュータを持っていないことです。私はタスクとパフォーマンスについて新しい質問をするかもしれません。@ TaW @Maarten – Jandy