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)閉事件中進行動態(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#通過System.CommandLine快速生成支持命令行的應(yīng)用程序
這篇文章介紹了C#通過System.CommandLine快速生成支持命令行應(yīng)用程序的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07
關(guān)于C#10 新特性 Lambda 優(yōu)化
這篇文章主要介紹了C# 10 新特性 Lambda 優(yōu)化,C# 10 對于 Lambda 做了很多的優(yōu)化,我們可以在 C# 中更加方便地使用委托和 Lambda 了,下面就來看一些示例,需要的朋友也可以參考一下2021-11-11

