Frm_Main.cs
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace PopupForm
11 {
12 public partial class Frm_Main : Form
13 {
14 public Frm_Main()
15 {
16 InitializeComponent();
17 }
18
19 private void display_Click(object sender, EventArgs e)
20 {
21 Frm_Info.Instance().ShowForm();//显示窗体
22 }
23
24 private void close_Click(object sender, EventArgs e)
25 {
26 Frm_Info.Instance().CloseForm();//隐藏窗体
27 }
28 }
29 }
Frm_Main.designer.cs
View Code
1 namespace PopupForm
2 {
3 partial class Frm_Main
4 {
5 /// <summary>
6 /// Required designer variable.
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// Clean up any resources being used.
12 /// </summary>
13 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
14 protected override void Dispose(bool disposing)
15 {
16 if (disposing && (components != null))
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }
22
23 #region Windows Form Designer generated code
24
25 /// <summary>
26 /// Required method for Designer support - do not modify
27 /// the contents of this method with the code editor.
28 /// </summary>
29 private void InitializeComponent()
30 {
31 this.display = new System.Windows.Forms.Button();
32 this.close = new System.Windows.Forms.Button();
33 this.groupBox1 = new System.Windows.Forms.GroupBox();
34 this.groupBox1.SuspendLayout();
35 this.SuspendLayout();
36 //
37 // display
38 //
39 this.display.Location = new System.Drawing.Point(16, 42);
40 this.display.Name = "display";
41 this.display.Size = new System.Drawing.Size(75, 23);
42 this.display.TabIndex = 0;
43 this.display.Text = "显示";
44 this.display.UseVisualStyleBackColor = true;
45 this.display.Click += new System.EventHandler(this.display_Click);
46 //
47 // close
48 //
49 this.close.Location = new System.Drawing.Point(107, 42);
50 this.close.Name = "close";
51 this.close.Size = new System.Drawing.Size(75, 23);
52 this.close.TabIndex = 1;
53 this.close.Text = "隐藏";
54 this.close.UseVisualStyleBackColor = true;
55 this.close.Click += new System.EventHandler(this.close_Click);
56 //
57 // groupBox1
58 //
59 this.groupBox1.Controls.Add(this.close);
60 this.groupBox1.Controls.Add(this.display);
61 this.groupBox1.Location = new System.Drawing.Point(12, 12);
62 this.groupBox1.Name = "groupBox1";
63 this.groupBox1.Size = new System.Drawing.Size(200, 100);
64 this.groupBox1.TabIndex = 2;
65 this.groupBox1.TabStop = false;
66 this.groupBox1.Text = "操作类型";
67 //
68 // Frm_Main
69 //
70 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
71 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
72 this.ClientSize = new System.Drawing.Size(220, 122);
73 this.Controls.Add(this.groupBox1);
74 this.MaximizeBox = false;
75 this.MinimizeBox = false;
76 this.Name = "Frm_Main";
77 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
78 this.Text = "从桌面右下角显示的Popup窗口提醒";
79 this.groupBox1.ResumeLayout(false);
80 this.ResumeLayout(false);
81
82 }
83
84 #endregion
85
86 private System.Windows.Forms.Button display;
87 private System.Windows.Forms.Button close;
88 private System.Windows.Forms.GroupBox groupBox1;
89 }
90 }
Frm_Info.cs
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Runtime.InteropServices;
10
11 namespace PopupForm
12 {
13 public partial class Frm_Info :System.Windows.Forms.Form
14 {
15 #region 声明的变量
16 private System.Drawing.Rectangle Rect;//定义一个存储矩形框的数组
17 private FormState InfoStyle = FormState.Hide;//定义变量为隐藏
18 static private Frm_Info dropDownForm = new Frm_Info();//实例化当前窗体
19 private static int AW_HIDE = 0x00010000; //该变量表示动画隐藏窗体
20 private static int AW_SLIDE = 0x00040000;//该变量表示出现滑行效果的窗体
21 private static int AW_VER_NEGATIVE = 0x00000008;//该变量表示从下向上开屏
22 private static int AW_VER_POSITIVE = 0x00000004;//该变量表示从上向下开屏
23 #endregion
24
25 #region 该窗体的构造方法
26 public Frm_Info()
27 {
28 InitializeComponent();
29 //初始化工作区大小
30 System.Drawing.Rectangle rect = System.Windows.Forms.Screen.GetWorkingArea(this);//实例化一个当前窗口的对象
31 this.Rect = new System.Drawing.Rectangle(rect.Right - this.Width - 1,rect.Bottom - this.Height - 1,this.Width,this.Height);//为实例化的对象创建工作区域
32 }
33 #endregion
34
35 #region 调用API函数显示窗体
36 [DllImportAttribute("user32.dll")]
37 private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
38 #endregion
39
40 #region 鼠标控制图片的变化
41 private void pictureBox1_MouseEnter(object sender, EventArgs e)
42 {
43 pictureBox1.Image = imageList1.Images[1];//设定当鼠标进入PictureBox控件时PictureBox控件的图片
44 }
45
46 private void pictureBox1_MouseLeave(object sender, EventArgs e)
47 {
48 pictureBox1.Image = imageList1.Images[0]; //设定当鼠标离开PictureBox控件时PictureBox控件的图片
49 }
50 #endregion
51
52 #region 定义标识窗体移动状态的枚举值
53 protected enum FormState
54 {
55
56 Hide=0,//隐藏窗体
57 Display=1,//显示窗体
58 Displaying=2,//显示窗体中
59 Hiding=3 //隐藏窗体中
60 }
61 #endregion
62
63 #region 用属性标识当前状态
64 protected FormState FormNowState
65 {
66 get { return this.InfoStyle; } //返回窗体的当前状态
67 set { this.InfoStyle = value; } //设定窗体当前状态的值
68 }
69 #endregion
70
71 #region 显示窗体
72 public void ShowForm()
73 {
74 switch (this.FormNowState)
75 {
76 case FormState.Hide:
77 if (this.Height <= this.Rect.Height - 192)//当窗体没有完全显示时
78 this.SetBounds(Rect.X, this.Top - 192, Rect.Width, this.Height + 192);//使窗体不断上移
79 else
80 {
81 this.SetBounds(Rect.X,Rect.Y,Rect.Width,Rect.Height);//设置当前窗体的边界
82 }
83 AnimateWindow(this.Handle, 800, AW_SLIDE + AW_VER_NEGATIVE);//动态显示本窗体
84 break;
85 }
86 }
87 #endregion
88
89 #region 关闭窗体
90 public void CloseForm()
91 {
92 AnimateWindow(this.Handle,800,AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);//动画隐藏窗体
93 this.FormNowState = FormState.Hide;//设定当前窗体的状态为隐藏
94 }
95 #endregion
96
97 #region 返回当前窗体的实例化对象
98 static public Frm_Info Instance()
99 {
100 return dropDownForm; //返回当前窗体的实例化对象
101 }
102 #endregion
103 }
104 }
Frm_Info.designer.cs
View Code
1 namespace PopupForm
2 {
3 partial class Frm_Info
4 {
5 /// <summary>
6 /// 必需的设计器变量。
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// 清理所有正在使用的资源。
12 /// </summary>
13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14 protected override void Dispose(bool disposing)
15 {
16 if (disposing && (components != null))
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }
22
23 #region Windows 窗体设计器生成的代码
24
25 /// <summary>
26 /// 设计器支持所需的方法 - 不要
27 /// 使用代码编辑器修改此方法的内容。
28 /// </summary>
29 private void InitializeComponent()
30 {
31 this.components = new System.ComponentModel.Container();
32 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Frm_Info));
33 this.imageList1 = new System.Windows.Forms.ImageList(this.components);
34 this.pictureBox1 = new System.Windows.Forms.PictureBox();
35 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
36 this.SuspendLayout();
37 //
38 // imageList1
39 //
40 this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
41 this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
42 this.imageList1.Images.SetKeyName(0,"Close2.bmp");
43 this.imageList1.Images.SetKeyName(1,"Close1.bmp");
44 //
45 // pictureBox1
46 //
47 this.pictureBox1.Location = new System.Drawing.Point(246,7);
48 this.pictureBox1.Name = "pictureBox1";
49 this.pictureBox1.Size = new System.Drawing.Size(19,19);
50 this.pictureBox1.TabIndex = 1;
51 this.pictureBox1.TabStop = false;
52 //
53 // MainForm
54 //
55 this.AutoScaleDimensions = new System.Drawing.SizeF(6F,12F);
56 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
57 this.BackColor = System.Drawing.SystemColors.HotTrack;
58 this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
59 this.ClientSize = new System.Drawing.Size(269,163);
60 this.ControlBox = false;
61 this.Controls.Add(this.pictureBox1);
62 this.ForeColor = System.Drawing.SystemColors.ControlText;
63 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
64 this.Name = "MainForm";
65 this.ShowInTaskbar = false;
66 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
67 this.Text = "制作下拉窗体";
68 this.TopMost = true;
69 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
70 this.ResumeLayout(false);
71
72 }
73
74 #endregion
75
76 private System.Windows.Forms.ImageList imageList1;
77 private System.Windows.Forms.PictureBox pictureBox1;
78 }
79 }
作者:墨明棋妙
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。