C# 线条动画
需要创建一个动画,该动画将在单击按钮时激活。我只想在窗体的边缘上使用通常的动画。按钮1-左右两侧的两个运行条,通向底部。按钮2-左右两条连续条纹向上。我真的需要这个,但我不知道怎么做。下面是一个我需要的例子,但这个动画在程序顶部创建了一个运行条C# 线条动画,c#,winforms,C#,Winforms,需要创建一个动画,该动画将在单击按钮时激活。我只想在窗体的边缘上使用通常的动画。按钮1-左右两侧的两个运行条,通向底部。按钮2-左右两条连续条纹向上。我真的需要这个,但我不知道怎么做。下面是一个我需要的例子,但这个动画在程序顶部创建了一个运行条 public partial class Form1 : Form { Timer tmr; public Form1() { InitializeComponent(); this.MouseDo
public partial class Form1 : Form
{
Timer tmr;
public Form1()
{
InitializeComponent();
this.MouseDoubleClick += Form1_MouseDoubleClick;
this.Paint += Form1_Paint;
tmr = new Timer();
tmr.Interval = 10;
tmr.Tick += tmr_Tick;
}
int x;
int step = 5;
void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
tmr.Stop();
x = 0;
tmr.Start();
}
void tmr_Tick(object sender, EventArgs e)
{
x += step;
if (x > this.Width)
{
x = 0;
(sender as Timer).Stop();
}
this.Invalidate();
}
void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Red, 0, 0, x, 4);
}
}
很难理解你想要什么,但如果我理解正确:
void Form1_Paint(object sender, PaintEventArgs e)
{
using(Pen pen = new Pen(Color.Red, 4)){
e.Graphics.drawLine(pen, 0, 0, 0, x);
e.Graphics.drawLine(pen, Width, x, 0, 0);
}
}
我是在没有IDE的情况下输入的,可能会有输入错误。你自己修吧:
大多数显示器的运行频率为60hz,即每帧约17ms,所以根据显示器刷新率,您应该每17ms更新一次,甚至更好
但有一个问题:计时器并没有那个么高的分辨率。在我的情况下,它只能每30毫秒刷新一次。
昨晚我发现了这个。我想今天我得做我自己的定时器
这是我的迷你图书馆。你感兴趣的东西有:动画定时器、动画师、材料文本框。你能发布一张演示效果的图片吗?我很难理解你的意思。