服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C# - C#实现系统桌面右下角弹框

C#实现系统桌面右下角弹框

2023-02-28 13:42芝麻粒儿 C#

这篇文章主要为大家详细介绍了C#如何实现系统桌面右下角弹框,文中的示例代码讲解详细,对我们学习C#有一定的帮助,感兴趣的小伙伴可以跟随小编一起了解一下

实践过程

效果

C#实现系统桌面右下角弹框

代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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(); //隐藏窗体
           //关闭窗体
           this.Close();
       }
   }
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
public partial class DropDownForm : System.Windows.Forms.Form
 {
     #region 声明的变量
 
     private System.Drawing.Rectangle Rect; //定义一个存储矩形框的数组
     private FormState InfoStyle = FormState.Hide; //定义变量为隐藏
     static private DropDownForm dropDownForm = new DropDownForm(); //实例化当前窗体
     private static int AW_HIDE = 0x00010000;
     private static int AW_SLIDE = 0x00040000;
     private static int AW_VER_NEGATIVE = 0x00000008;
 
     #endregion
 
     #region 该窗体的构造方法
 
     public DropDownForm()
     {
         InitializeComponent();
         //初始化工作区大小
         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 调用API函数显示窗体
 
     [DllImportAttribute("user32.dll")]
     private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
 
     #endregion
 
     #region 鼠标控制图片的变化
 
     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 定义标识窗体移动状态的枚举值
 
     protected enum FormState
     {
         //隐藏窗体
         Hide = 0,
 
         //显示窗体
         Display = 1,
 
         //显示窗体中
         Displaying = 2,
 
         //隐藏窗体中
         Hiding = 3
     }
 
     #endregion
 
     #region 用属性标识当前状态
 
     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) //当窗体没有完全显示时
                     this.SetBounds(Rect.X, this.Top - 192, Rect.Width, this.Height + 192); //使窗体不断上移
                 else
                 {
                     this.SetBounds(Rect.X, Rect.Y, Rect.Width, Rect.Height); //设置当前窗体的边界
                     this.FormNowState = FormState.Display; //设置当前窗体的操作状态为显示
                 }
 
                 AnimateWindow(this.Handle, 800, AW_SLIDE + AW_VER_NEGATIVE); //动态显示本窗体
                 break;
         }
     }
 
     #endregion
 
     #region 关闭窗体
 
     public void CloseForm()
     {
         switch (this.FormNowState)
         {
             case FormState.Display: //显示当前窗体
                 if (this.Top <= this.Rect.Bottom - 192) //如果窗体没有完全隐藏
                 {
                     this.SetBounds(Rect.X, this.Top + 192, Rect.Width, this.Height - 192); //使窗体不断下移
                 }
                 else
                 {
                     this.Close(); //隐藏当前窗体
                     this.FormNowState = FormState.Hide; //设置窗体的操作状态为隐藏
                 }
 
                 break;
         }
     }
 
     #endregion
 
     #region 返回当前窗体的实例化对象
 
     static public DropDownForm Instance()
     {
         return dropDownForm;
     }
 
     #endregion
 
     #region 在窗体的关闭事件中进行动态关闭
 
     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#实现系统桌面右下角弹框的详细内容,更多关于C#桌面弹框的资料请关注服务器之家其它相关文章!

原文链接:https://zhima.blog.csdn.net/article/details/128021475

延伸 · 阅读

精彩推荐
  • C#C# 使用AE获取feature的属性及字段操作

    C# 使用AE获取feature的属性及字段操作

    这篇文章主要介绍了C# 使用AE获取feature的属性及字段操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    南方北先生9752022-10-27
  • C#C#实现的简单链表类实例

    C#实现的简单链表类实例

    这篇文章主要介绍了C#实现的简单链表类,涉及C#针对链表的定义、实现及链表节点的增加、删除与修改技巧,具有一定参考借鉴价值,需要的朋友可以参考下...

    北风其凉6892021-10-19
  • C#详解.NET 6如何实现获取当前登录用户信息

    详解.NET 6如何实现获取当前登录用户信息

    这篇文章主要介绍了.NET 6在应用开发时是如何实现当前登陆用户信息获取的,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起了解一下...

    CODE4NOTHING8932022-12-21
  • C#C#向Word插入排版精良的TextBox

    C#向Word插入排版精良的TextBox

    这篇文章主要为大家详细介绍了C#向Word插入排版精良的Text Box的相关方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    Yesi9782021-12-07
  • C#C#的Socket实现UDP协议通信示例代码

    C#的Socket实现UDP协议通信示例代码

    本篇文章主要介绍了C#的Socket实现UDP协议通信示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    黄文博11992021-12-22
  • C#C#通过HttpWebRequest发送带有JSON Body的POST请求实现

    C#通过HttpWebRequest发送带有JSON Body的POST请求实现

    本文主要介绍了C#通过HttpWebRequest发送带有JSON Body的POST请求实现,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一...

    NeverSettle1015062022-12-02
  • C#C# 计算标准偏差相当于Excel中的STDEV函数实例

    C# 计算标准偏差相当于Excel中的STDEV函数实例

    下面小编就为大家带来一篇C# 计算标准偏差相当于Excel中的STDEV函数实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看...

    C#教程网8712021-12-22
  • C#C# 实现ADSL自动断网和拨号的方法(适用于拨号用户)

    C# 实现ADSL自动断网和拨号的方法(适用于拨号用户)

    下面小编就为大家带来一篇C# 实现ADSL自动断网和拨号的方法(适用于拨号用户)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编...

    C#教程网8252021-12-14