CodeGo.net>如何改变形式与动画?

如何在Win应用程序中使用动画(例如,淡入淡出,Cutl Up等)更改表格?

我有两个表格Form1,Form2.
我在form1中,上面有一个按钮,单击按钮时我想更改表格.

//button click
Form2 f2=new Form2();
this.hide();
f2.show();

解决方法:

您可以使用AnimateWindow(),定义新的表单类并重写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 onl oad(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;
}
上一篇:禁用单击复选框,但不能从后面的代码


下一篇:C#中的布局管理器