c#之利用API函數(shù)實(shí)現(xiàn)動(dòng)畫窗體的方法詳解
更新時(shí)間:2013年06月08日 15:36:44 作者:
本篇文章是對(duì)c#中利用API函數(shù)實(shí)現(xiàn)動(dòng)畫窗體的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
這里主要利用API函數(shù)Animate Window實(shí)現(xiàn)窗體左右,上下,擴(kuò)展,淡入滑動(dòng)或滾動(dòng)動(dòng)畫效果,步驟如下:
1.新建窗體,使用2個(gè)GroupBox控件。
2.在控件1中添加2個(gè)RadioButton控件,并設(shè)置Text分別為“滾動(dòng)窗體”,“滑動(dòng)窗體”,并使前者Checked設(shè)置為True。
3.在空間2中添加6個(gè)按鈕,Text分別為“自左向右動(dòng)畫”,“自右向左動(dòng)畫”,“自上向下動(dòng)畫”,“自下向上動(dòng)畫”,“向外擴(kuò)展動(dòng)畫”,“淡入動(dòng)畫窗體”。
4.添加一新的Window窗體,設(shè)置Text為“動(dòng)畫窗體”。設(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 = "自左向右滾動(dòng)窗體動(dòng)畫效果";
}
else
{
myf.Text = "自左向右滑動(dòng)窗體動(dòng)畫效果";
}
myf.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自右向左滾動(dòng)窗體動(dòng)畫效果";
}
else
{
myf.Text = "自右向左滑動(dòng)窗體動(dòng)畫效果";
}
myf.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自上向下滾動(dòng)窗體動(dòng)畫效果";
}
else
{
myf.Text = "自上向下滑動(dòng)窗體動(dòng)畫效果";
}
myf.Show();
}
private void button5_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自下向上滾動(dòng)窗體動(dòng)畫效果";
}
else
{
myf.Text = "自下向上滑動(dòng)窗體動(dòng)畫效果";
}
myf.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "向外擴(kuò)展窗體動(dòng)畫效果";
myf.Show();
}
private void button6_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "淡入窗體動(dòng)畫效果";
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 == "自左向右滾動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle,2000,AW_HOR_POSITIVE);
}
if (this.Text == "自左向右滑動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE+AW_HOR_POSITIVE);
}
if (this.Text == "自右向左滾動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_HOR_NEGATIVE);
}
if (this.Text == "自右向左滑動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_HOR_NEGATIVE);
}
if (this.Text == "自上向下滾動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_VER_POSITIVE);
}
if (this.Text == "自上向下滑動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_POSITIVE);
}
if (this.Text == "自下向上滾動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_VER_NEGATIVE);
}
if (this.Text == "自下向上滑動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_NEGATIVE);
}
if (this.Text == "向外擴(kuò)展窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_CENTER);
}
if (this.Text == "淡入窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_BLEND);
}
}//yinyiniao's Blog
1.新建窗體,使用2個(gè)GroupBox控件。
2.在控件1中添加2個(gè)RadioButton控件,并設(shè)置Text分別為“滾動(dòng)窗體”,“滑動(dòng)窗體”,并使前者Checked設(shè)置為True。
3.在空間2中添加6個(gè)按鈕,Text分別為“自左向右動(dòng)畫”,“自右向左動(dòng)畫”,“自上向下動(dòng)畫”,“自下向上動(dòng)畫”,“向外擴(kuò)展動(dòng)畫”,“淡入動(dòng)畫窗體”。
4.添加一新的Window窗體,設(shè)置Text為“動(dòng)畫窗體”。設(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 = "自左向右滾動(dòng)窗體動(dòng)畫效果";
}
else
{
myf.Text = "自左向右滑動(dòng)窗體動(dòng)畫效果";
}
myf.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自右向左滾動(dòng)窗體動(dòng)畫效果";
}
else
{
myf.Text = "自右向左滑動(dòng)窗體動(dòng)畫效果";
}
myf.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自上向下滾動(dòng)窗體動(dòng)畫效果";
}
else
{
myf.Text = "自上向下滑動(dòng)窗體動(dòng)畫效果";
}
myf.Show();
}
private void button5_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if (radioButton1.Checked == true)
{
myf.Text = "自下向上滾動(dòng)窗體動(dòng)畫效果";
}
else
{
myf.Text = "自下向上滑動(dòng)窗體動(dòng)畫效果";
}
myf.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "向外擴(kuò)展窗體動(dòng)畫效果";
myf.Show();
}
private void button6_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
myf.Text = "淡入窗體動(dòng)畫效果";
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 == "自左向右滾動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle,2000,AW_HOR_POSITIVE);
}
if (this.Text == "自左向右滑動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE+AW_HOR_POSITIVE);
}
if (this.Text == "自右向左滾動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_HOR_NEGATIVE);
}
if (this.Text == "自右向左滑動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_HOR_NEGATIVE);
}
if (this.Text == "自上向下滾動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_VER_POSITIVE);
}
if (this.Text == "自上向下滑動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_POSITIVE);
}
if (this.Text == "自下向上滾動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_VER_NEGATIVE);
}
if (this.Text == "自下向上滑動(dòng)窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_NEGATIVE);
}
if (this.Text == "向外擴(kuò)展窗體動(dòng)畫效果")
{
AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_CENTER);
}
if (this.Text == "淡入窗體動(dòng)畫效果")
{
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)時(shí)間、獲取硬盤序列號(hào)
- C#獲取USB事件API實(shí)例分析
- C# API中模型與它們的接口設(shè)計(jì)詳解
相關(guān)文章
C#使用csvhelper實(shí)現(xiàn)csv的基本操作
CsvHelper 是一個(gè)用于讀寫 CSV 文件的.NET庫(kù),極其快速,靈活且易于使用,CsvHelper 建立在.NET Standard 2.0 之上,幾乎可以在任何地方運(yùn)行,本文給大家介紹了C#使用csvhelper實(shí)現(xiàn)csv的基本操作,需要的朋友可以參考下2024-07-07
解析C#彩色圖像灰度化算法的實(shí)現(xiàn)代碼詳解
本篇文章是對(duì)C#中彩色圖像灰度化算法的實(shí)現(xiàn)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
C# 讀寫自定義的Config文件的實(shí)現(xiàn)方法
本文主要介紹了C# 讀寫自定義的Config文件的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07
Unity實(shí)現(xiàn)簡(jiǎn)單虛擬搖桿
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)簡(jiǎn)單虛擬搖桿,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04
C#確保只有一個(gè)實(shí)例在運(yùn)行的方法
這篇文章主要介紹了C#確保只有一個(gè)實(shí)例在運(yùn)行的方法,涉及C#進(jìn)程操作的相關(guān)技巧,需要的朋友可以參考下2015-05-05
Winform消除button按下出現(xiàn)的虛線簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要介紹了Winform消除button按下出現(xiàn)的虛線簡(jiǎn)單實(shí)現(xiàn)方法,通過重寫button設(shè)置Selectable參數(shù)實(shí)現(xiàn)該功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08

