C# 如何用动画改变形式?
如何在win应用程序中更改动画形式(如淡入淡出、剪切等) 我有两张表格,表格一,表格二。 我在form1中,上面有一个按钮,我想在单击按钮时更改表单C# 如何用动画改变形式?,c#,winforms,animation,C#,Winforms,Animation,如何在win应用程序中更改动画形式(如淡入淡出、剪切等) 我有两张表格,表格一,表格二。 我在form1中,上面有一个按钮,我想在单击按钮时更改表单 //button click Form2 f2=new Form2(); this.hide(); f2.show(); 在不深入代码本身的细节的情况下,我发现了一个处理类似主题的问题: 这个问题将我引向一个名为的库,我认为它完全满足您的需要。您可以使用它,定义一个新的表单类并重写OnLoad(),以显示具有所需效果的表单 // Console
//button click
Form2 f2=new Form2();
this.hide();
f2.show();
在不深入代码本身的细节的情况下,我发现了一个处理类似主题的问题: 这个问题将我引向一个名为的库,我认为它完全满足您的需要。您可以使用它,定义一个新的表单类并重写
OnLoad()
,以显示具有所需效果的表单
// Console Application
// Load System.Windows.Forms reference.
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
class SlidingForm: System.Windows.Forms.Form
{
const int AW_ACTIVATE = 0X20000;
const int AW_SLIDE = 0X40000;
const int AW_HOR_POSITIVE = 0X1;
protected override void OnLoad(System.EventArgs e)
{
AnimateWindow(this.Handle, 1000, AW_ACTIVATE | AW_SLIDE | AW_HOR_POSITIVE);
base.OnLoad(e);
}
}
void Main()
{
var frm = new SlidingForm().ShowDialog;
}
根据请求隐藏PictureBox控件的示例代码:
private void button1_Click(object sender, EventArgs e)
{
const int AW_HIDE = 0x00010000;
const int AW_SLIDE = 0x00040000;
const int AW_HOR_NEGATIVE = 0x00000002;
const int AW_HOR_POSITIVE = 0x00000001;
// Toggle show/hide
AnimateWindow(pictureBox1.Handle, 1000, (pictureBox1.Visible) ? (AW_HIDE | AW_HOR_NEGATIVE) : (AW_HOR_POSITIVE) | AW_SLIDE);
pictureBox1.Visible ^= true;
}
你有什么例外?它工作不正常吗?例如,我使用此代码作为背景色,但什么也没有发生:Transition.run(这是“BackColor”,color.Red,new TransitionType_Linear(1000));非常感谢。可以将其用于picturebox之类的控件吗?是的,通常可以将控件的句柄(如
picturebox
传递到AnimateWindow
函数)。例如:AnimateWindow(PictureBox1.Handle,1000,AW_VER_NEGATIVE | AW_SLIDE | AW_HIDE)代码>将隐藏带有垂直滑动效果的PictureBox
控件。我使用此代码但不工作:动画窗口(pictureBox1.Handle,5000,AW_激活| AW|u混合| AW|u HOR_阳性);AnimateWindow返回bool,而不是int。使用它引发Win32异常,以便OP知道他使用了错误。无法激活子窗口。@HansPassant当BOOL
type被映射到int时,在这里使用int有什么缺点吗?