c#之利用API函數(shù)實(shí)現(xiàn)動畫窗體的方法詳解
更新時間:2013年06月08日 15:36:44 作者:
本篇文章是對c#中利用API函數(shù)實(shí)現(xiàn)動畫窗體的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
這里主要利用API函數(shù)Animate Window實(shí)現(xiàn)窗體左右,上下,擴(kuò)展,淡入滑動或滾動動畫效果,步驟如下:
1.新建窗體,使用2個GroupBox控件。
2.在控件1中添加2個RadioButton控件,并設(shè)置Text分別為“滾動窗體”,“滑動窗體”,并使前者Checked設(shè)置為True。
3.在空間2中添加6個按鈕,Text分別為“自左向右動畫”,“自右向左動畫”,“自上向下動畫”,“自下向上動畫”,“向外擴(kuò)展動畫”,“淡入動畫窗體”。
4.添加一新的Window窗體,設(shè)置Text為“動畫窗體”。設(shè)置其“BackgroundImage”屬性,導(dǎo)入一張要加載的圖像,然后設(shè)置其“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 = "向外擴(kuò)展窗體動畫效果";
myf.Show();
}
private void button6_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "淡入窗體動畫效果";
myf.Show();
}
6.雙擊Form2窗體,進(jìn)入代碼視圖。首先定義公用變量,具體代碼如下:
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 == "向外擴(kuò)展窗體動畫效果")
{
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控件,并設(shè)置Text分別為“滾動窗體”,“滑動窗體”,并使前者Checked設(shè)置為True。
3.在空間2中添加6個按鈕,Text分別為“自左向右動畫”,“自右向左動畫”,“自上向下動畫”,“自下向上動畫”,“向外擴(kuò)展動畫”,“淡入動畫窗體”。
4.添加一新的Window窗體,設(shè)置Text為“動畫窗體”。設(shè)置其“BackgroundImage”屬性,導(dǎo)入一張要加載的圖像,然后設(shè)置其“BackgroundImageLayout”屬性為“Stretch”。
5.各按鈕事件主要代碼如下:
復(fù)制代碼 代碼如下:
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 = "向外擴(kuò)展窗體動畫效果";
myf.Show();
}
private void button6_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "淡入窗體動畫效果";
myf.Show();
}
6.雙擊Form2窗體,進(jìn)入代碼視圖。首先定義公用變量,具體代碼如下:
復(fù)制代碼 代碼如下:
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窗體添加加載事件代碼,具體如下:
復(fù)制代碼 代碼如下:
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 == "向外擴(kuò)展窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_CENTER);
}
if (this.Text == "淡入窗體動畫效果")
{
AnimateWindow(this.Handle, 2000, AW_BLEND);
}
}//yinyiniao's Blog
您可能感興趣的文章:
- C# web api返回類型設(shè)置為json的兩種方法
- C#中通過API實(shí)現(xiàn)的打印類 實(shí)例代碼
- C#實(shí)現(xiàn)快遞api接口調(diào)用方法
- C#通過WIN32 API實(shí)現(xiàn)嵌入程序窗體
- 使用C#調(diào)用系統(tǒng)API實(shí)現(xiàn)內(nèi)存注入的代碼
- ASP.NET(C#) Web Api通過文件流下載文件的實(shí)例
- c#調(diào)用api控制windows關(guān)機(jī)示例(可以重啟/注銷)
- C#利用win32 Api 修改本地系統(tǒng)時間、獲取硬盤序列號
- C#獲取USB事件API實(shí)例分析
- C# API中模型與它們的接口設(shè)計詳解
相關(guān)文章
C#調(diào)用HTTP POST請求上傳圖片的示例代碼
現(xiàn)在很多B/S系統(tǒng)的開發(fā)都是通過API方式來進(jìn)行的,一般服務(wù)端會開放一個API接口,客戶端調(diào)用API接口來實(shí)現(xiàn)圖片或文件上傳的功能,感興趣的可以了解一下2021-05-05c#檢測usb設(shè)備撥插類庫USBClassLibrary分享
這篇文章主要介紹了c#檢測usb設(shè)備撥插類庫USBClassLibrary的簡單示例,需要的朋友可以參考下2014-04-04Unity的Console的控制類LogEntries深入解析與實(shí)用案例
這篇文章主要為大家介紹了Unity的Console的控制類LogEntries深入解析與實(shí)用案例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07c# 自定義值類型一定不要忘了重寫Equals,否則性能和空間雙雙堪憂
這篇文章主要介紹了c# 自定義值類型一定不要忘了重寫Equals,幫助大家提高c# 程序的性能,感興趣的朋友可以了解下2020-08-08c#?Task.Wait()與awaiat?Task異常處理的區(qū)別說明
這篇文章主要介紹了c#?Task.Wait()與awaiat?Task異常處理的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06