C#實現(xiàn)系統(tǒng)桌面右下角彈框
更新時間:2023年01月05日 11:10:21 作者:芝麻粒兒
這篇文章主要為大家詳細(xì)介紹了C#如何實現(xiàn)系統(tǒng)桌面右下角彈框,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
實踐過程
效果
代碼
public partial class GroundForm : Form { public GroundForm() { InitializeComponent(); } private void display_Click(object sender, EventArgs e) { DropDownForm.Instance().ShowForm(); //顯示窗體 } private void close_Click(object sender, EventArgs e) { DropDownForm.Instance().CloseForm(); //隱藏窗體 //關(guān)閉窗體 this.Close(); } }
public partial class DropDownForm : System.Windows.Forms.Form { #region 聲明的變量 private System.Drawing.Rectangle Rect; //定義一個存儲矩形框的數(shù)組 private FormState InfoStyle = FormState.Hide; //定義變量為隱藏 static private DropDownForm dropDownForm = new DropDownForm(); //實例化當(dāng)前窗體 private static int AW_HIDE = 0x00010000; private static int AW_SLIDE = 0x00040000; private static int AW_VER_NEGATIVE = 0x00000008; #endregion #region 該窗體的構(gòu)造方法 public DropDownForm() { InitializeComponent(); //初始化工作區(qū)大小 System.Drawing.Rectangle rect = System.Windows.Forms.Screen.GetWorkingArea(this); this.Rect = new System.Drawing.Rectangle(rect.Right - this.Width - 1, rect.Bottom - this.Height - 1, this.Width, this.Height); } #endregion #region 調(diào)用API函數(shù)顯示窗體 [DllImportAttribute("user32.dll")] private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags); #endregion #region 鼠標(biāo)控制圖片的變化 private void pictureBox1_MouseEnter(object sender, EventArgs e) { for (int i = 0; i < imageList1.Images.Count; i++) { if (i == 1) pictureBox1.Image = imageList1.Images[i]; } } private void pictureBox1_MouseLeave(object sender, EventArgs e) { for (int i = 0; i < imageList1.Images.Count; i++) { if (i == 0) pictureBox1.Image = imageList1.Images[i]; } } #endregion #region 定義標(biāo)識窗體移動狀態(tài)的枚舉值 protected enum FormState { //隱藏窗體 Hide = 0, //顯示窗體 Display = 1, //顯示窗體中 Displaying = 2, //隱藏窗體中 Hiding = 3 } #endregion #region 用屬性標(biāo)識當(dāng)前狀態(tài) protected FormState FormNowState { get { return this.InfoStyle; } set { this.InfoStyle = value; } } #endregion #region 顯示窗體 public void ShowForm() { switch (this.FormNowState) { case FormState.Hide: if (this.Height <= this.Rect.Height - 192) //當(dāng)窗體沒有完全顯示時 this.SetBounds(Rect.X, this.Top - 192, Rect.Width, this.Height + 192); //使窗體不斷上移 else { this.SetBounds(Rect.X, Rect.Y, Rect.Width, Rect.Height); //設(shè)置當(dāng)前窗體的邊界 this.FormNowState = FormState.Display; //設(shè)置當(dāng)前窗體的操作狀態(tài)為顯示 } AnimateWindow(this.Handle, 800, AW_SLIDE + AW_VER_NEGATIVE); //動態(tài)顯示本窗體 break; } } #endregion #region 關(guān)閉窗體 public void CloseForm() { switch (this.FormNowState) { case FormState.Display: //顯示當(dāng)前窗體 if (this.Top <= this.Rect.Bottom - 192) //如果窗體沒有完全隱藏 { this.SetBounds(Rect.X, this.Top + 192, Rect.Width, this.Height - 192); //使窗體不斷下移 } else { this.Close(); //隱藏當(dāng)前窗體 this.FormNowState = FormState.Hide; //設(shè)置窗體的操作狀態(tài)為隱藏 } break; } } #endregion #region 返回當(dāng)前窗體的實例化對象 static public DropDownForm Instance() { return dropDownForm; } #endregion #region 在窗體的關(guān)閉事件中進(jìn)行動態(tài)關(guān)閉 private void DropDownForm_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; AnimateWindow(this.Handle, 800, AW_SLIDE + AW_VER_NEGATIVE + AW_HIDE); this.Close(); } #endregion }
以上就是C#實現(xiàn)系統(tǒng)桌面右下角彈框的詳細(xì)內(nèi)容,更多關(guān)于C#桌面彈框的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#調(diào)用FFmpeg操作音視頻的實現(xiàn)示例
本文主要介紹了C#調(diào)用FFmpeg操作音視頻的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-01-01gridview的buttonfield獲取該行的索引值(實例講解)
本篇文章主要介紹了gridview的buttonfield獲取該行的索引值(實例講解)需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01C#使用SqlDataAdapter對象獲取數(shù)據(jù)的方法
這篇文章主要介紹了C#使用SqlDataAdapter對象獲取數(shù)據(jù)的方法,結(jié)合實例形式較為詳細(xì)的分析了SqlDataAdapter對象獲取數(shù)據(jù)具體步驟與相關(guān)使用技巧,需要的朋友可以參考下2016-02-02