新手在C#这里,我想制作一个自定义的胜利形式,其行为如下:
这是我的版本,但是我无法看到它是如何工作的,只是卷起来才有效,但是当我第二次双击时,它并没有下载。
namespace WindowsFormsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool thisRolled = false;
public static void resiseMe(Form frm, int newHeight, bool maximIt)
{
if (newHeight > 27)
{
bool loopEnd = false;
if (maximIt == false)
{
while (loopEnd == false && frm.Height >= newHeight)
{
// ticks2 = Stopwatch.GetTimestamp();
int thisHeight = frm.Height--;
Application.DoEvents();
if (thisHeight == newHeight)
{
loopEnd = true;
}
//Thread.Sleep(2);
}
}
else
{
while (loopEnd == false && frm.Height <= newHeight)
{
int thisHeight = frm.Height++;
if (thisHeight == newHeight)
{
loopEnd = true;
}
}
}
}
}
protected override void OnDoubleClick(EventArgs e)
{
if (thisRolled == true)
{
resiseMe(this, 28, false);
}
else
{
resiseMe(this, 320, true);
}
base.OnDoubleClick(e);
}
protected override void OnSizeChanged(EventArgs e)
{
if (this.Height <= 50)
{
thisRolled = true;
}
else
{
thisRolled = false;
}
base.OnSizeChanged(e);
}
}
}
请有人帮忙/建议我如何使其发挥作用。
答案 0 :(得分:0)
尝试这可能会有所帮助
public static void resiseMe(Form frm, int newHeight)
{
new Task(() =>
{
int pause = 100;
int steps = 5;
int diff = newHeight - frm.Height;
int adjust = diff / steps;
for (int i = 0; i < steps; i++)
{
frm.Invoke(new MethodInvoker(()=>{
frm.Height += adjust;
frm.Refresh();
System.Threading.Thread.Sleep(pause);
}));
}
}).Start();
}
protected override void OnDoubleClick(EventArgs e)
{
if (thisRolled)
{
resiseMe(this, this.Height - 50);
}
else
{
resiseMe(this, this.Height + 50);
}
thisRolled = !thisRolled; // flip the thisRolled Value
base.OnDoubleClick(e);
}
如果你想加快动画,请减少pause
变量。
答案 1 :(得分:0)
thisRolled总是假的。
添加thisRolled = true;在你的第二个resiseMe循环中
此外,您的resiseMe目前是一种静态方法。因此,您需要将thisRolled声明为static(static bool thisRolled = false;)或从public static void resiseMe中删除静态