【发布时间】:2016-12-25 12:09:04
【问题描述】:
我想在按下按钮时将动画应用到我的按钮。在 WPF 中,我可以使用 Storyboard 和触发器来创建动画。这是一个例子:
<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 在这方面并不擅长。
-
对于无用的浮华,请继续使用 WPF..
-
是的,WPF 很好。但问题是我没有一台好的电脑。我可能会问一个关于任务和性能的新问题。@TaW @Maarten
-
在Windows窗体中为按钮实现平滑的动画发光效果并不难。
标签: c# .net winforms button custom-controls