实例介绍
【实例简介】
【实例截图】
【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
// Download by http://www.codefans.net
namespace DropDownForm
{
public partial class MainForm :System.Windows.Forms.Form
{
#region 声明的变量
private System.Drawing.Rectangle Rect;//定义一个存储矩形框的数组
private FormState InfoStyle = FormState.Hide;//定义变量为隐藏
static private MainForm dropDownForm = new MainForm();//实例化当前窗体
private static int AW_HIDE = 0x00010000; //该变量表示动画隐藏窗体
private static int AW_SLIDE = 0x00040000;//该变量表示出现滑行效果的窗体
private static int AW_VER_NEGATIVE = 0x00000008;//该变量表示从下向上开屏
private static int AW_VER_POSITIVE = 0x00000004;//该变量表示从上向下开屏
#endregion
#region 该窗体的构造方法
public MainForm()
{
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)
{
pictureBox1.Image = imageList1.Images[1];//设定当鼠标进入PictureBox控件时PictureBox控件的图片
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[0]; //设定当鼠标离开PictureBox控件时PictureBox控件的图片
}
#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);//设置当前窗体的边界
}
AnimateWindow(this.Handle, 800, AW_SLIDE AW_VER_NEGATIVE);//动态显示本窗体
break;
}
}
#endregion
#region 关闭窗体
public void CloseForm()
{
AnimateWindow(this.Handle,800,AW_SLIDE AW_VER_POSITIVE AW_HIDE); //动画隐藏窗体
this.FormNowState = FormState.Hide;//设定当前窗体的状态为隐藏
}
#endregion
#region 返回当前窗体的实例化对象
static public MainForm Instance()
{
return dropDownForm; //返回当前窗体的实例化对象
}
#endregion
}
}
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


支持(0) 盖楼(回复)