c#之利用API函數實現(xiàn)動畫窗體的方法詳解
更新時間:2013年06月08日 15:36:44 作者:
本篇文章是對c#中利用API函數實現(xiàn)動畫窗體的方法進行了詳細的分析介紹,需要的朋友參考下
這里主要利用API函數Animate Window實現(xiàn)窗體左右,上下,擴展,淡入滑動或滾動動畫效果,步驟如下:
1.新建窗體,使用2個GroupBox控件。
2.在控件1中添加2個RadioButton控件,并設置Text分別為“滾動窗體”,“滑動窗體”,并使前者Checked設置為True。
3.在空間2中添加6個按鈕,Text分別為“自左向右動畫”,“自右向左動畫”,“自上向下動畫”,“自下向上動畫”,“向外擴展動畫”,“淡入動畫窗體”。
4.添加一新的Window窗體,設置Text為“動畫窗體”。設置其“BackgroundImage”屬性,導入一張要加載的圖像,然后設置其“BackgroundImageLayout”屬性為“Stretch”。
5.各按鈕事件主要代碼如下:
private void button1_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自左向右滾動窗體動畫效果";
}
else
{
myf.Text = "自左向右滑動窗體動畫效果";
}
myf.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自右向左滾動窗體動畫效果";
}
else
{
myf.Text = "自右向左滑動窗體動畫效果";
}
myf.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自上向下滾動窗體動畫效果";
}
else
{
myf.Text = "自上向下滑動窗體動畫效果";
}
myf.Show();
}
private void button5_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自下向上滾動窗體動畫效果";
}
else
{
myf.Text = "自下向上滑動窗體動畫效果";
}
myf.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "向外擴展窗體動畫效果";
myf.Show();
}
private void button6_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "淡入窗體動畫效果";
myf.Show();
}
6.雙擊Form2窗體,進入代碼視圖。首先定義公用變量,具體代碼如下:
public const Int32 AW_HOR_POSITIVE = 0X00000001;
public const Int32 AW_HOR_NEGATIVE = 0X00000002;
public const Int32 AW_VER_POSITIVE = 0X00000004;
public const Int32 AW_VER_NEGATIVE = 0X00000008;
public const Int32 AW_CENTER = 0X00000010;
public const Int32 AW_HIDE = 0X00010000;
public const Int32 AW_ACTIVATE = 0X00020000;
public const Int32 AW_SLIDE = 0X00040000;
public const Int32 AW_BLEND = 0X00080000;
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags);
7.下面為Form2窗體添加加載事件代碼,具體如下:
private void Form2_Load(object sender, EventArgs e)
{
if (this.Text == "自左向右滾動窗體動畫效果")
{
AnimateWindow(this.Handle,2000,AW_HOR_POSITIVE);
}
if (this.Text == "自左向右滑動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE+AW_HOR_POSITIVE);
}
if (this.Text == "自右向左滾動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_HOR_NEGATIVE);
}
if (this.Text == "自右向左滑動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_HOR_NEGATIVE);
}
if (this.Text == "自上向下滾動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_VER_POSITIVE);
}
if (this.Text == "自上向下滑動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_POSITIVE);
}
if (this.Text == "自下向上滾動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_VER_NEGATIVE);
}
if (this.Text == "自下向上滑動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_NEGATIVE);
}
if (this.Text == "向外擴展窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_CENTER);
}
if (this.Text == "淡入窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_BLEND);
}
}//yinyiniao's Blog
1.新建窗體,使用2個GroupBox控件。
2.在控件1中添加2個RadioButton控件,并設置Text分別為“滾動窗體”,“滑動窗體”,并使前者Checked設置為True。
3.在空間2中添加6個按鈕,Text分別為“自左向右動畫”,“自右向左動畫”,“自上向下動畫”,“自下向上動畫”,“向外擴展動畫”,“淡入動畫窗體”。
4.添加一新的Window窗體,設置Text為“動畫窗體”。設置其“BackgroundImage”屬性,導入一張要加載的圖像,然后設置其“BackgroundImageLayout”屬性為“Stretch”。
5.各按鈕事件主要代碼如下:
復制代碼 代碼如下:
private void button1_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自左向右滾動窗體動畫效果";
}
else
{
myf.Text = "自左向右滑動窗體動畫效果";
}
myf.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自右向左滾動窗體動畫效果";
}
else
{
myf.Text = "自右向左滑動窗體動畫效果";
}
myf.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自上向下滾動窗體動畫效果";
}
else
{
myf.Text = "自上向下滑動窗體動畫效果";
}
myf.Show();
}
private void button5_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自下向上滾動窗體動畫效果";
}
else
{
myf.Text = "自下向上滑動窗體動畫效果";
}
myf.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "向外擴展窗體動畫效果";
myf.Show();
}
private void button6_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "淡入窗體動畫效果";
myf.Show();
}
6.雙擊Form2窗體,進入代碼視圖。首先定義公用變量,具體代碼如下:
復制代碼 代碼如下:
public const Int32 AW_HOR_POSITIVE = 0X00000001;
public const Int32 AW_HOR_NEGATIVE = 0X00000002;
public const Int32 AW_VER_POSITIVE = 0X00000004;
public const Int32 AW_VER_NEGATIVE = 0X00000008;
public const Int32 AW_CENTER = 0X00000010;
public const Int32 AW_HIDE = 0X00010000;
public const Int32 AW_ACTIVATE = 0X00020000;
public const Int32 AW_SLIDE = 0X00040000;
public const Int32 AW_BLEND = 0X00080000;
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags);
7.下面為Form2窗體添加加載事件代碼,具體如下:
復制代碼 代碼如下:
private void Form2_Load(object sender, EventArgs e)
{
if (this.Text == "自左向右滾動窗體動畫效果")
{
AnimateWindow(this.Handle,2000,AW_HOR_POSITIVE);
}
if (this.Text == "自左向右滑動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE+AW_HOR_POSITIVE);
}
if (this.Text == "自右向左滾動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_HOR_NEGATIVE);
}
if (this.Text == "自右向左滑動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_HOR_NEGATIVE);
}
if (this.Text == "自上向下滾動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_VER_POSITIVE);
}
if (this.Text == "自上向下滑動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_POSITIVE);
}
if (this.Text == "自下向上滾動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_VER_NEGATIVE);
}
if (this.Text == "自下向上滑動窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_NEGATIVE);
}
if (this.Text == "向外擴展窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_CENTER);
}
if (this.Text == "淡入窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_BLEND);
}
}//yinyiniao's Blog
相關文章
c#檢測usb設備撥插類庫USBClassLibrary分享
這篇文章主要介紹了c#檢測usb設備撥插類庫USBClassLibrary的簡單示例,需要的朋友可以參考下2014-04-04Unity的Console的控制類LogEntries深入解析與實用案例
這篇文章主要為大家介紹了Unity的Console的控制類LogEntries深入解析與實用案例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07c# 自定義值類型一定不要忘了重寫Equals,否則性能和空間雙雙堪憂
這篇文章主要介紹了c# 自定義值類型一定不要忘了重寫Equals,幫助大家提高c# 程序的性能,感興趣的朋友可以了解下2020-08-08c#?Task.Wait()與awaiat?Task異常處理的區(qū)別說明
這篇文章主要介紹了c#?Task.Wait()與awaiat?Task異常處理的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06