winform最小化及关闭提示
public PrintService()
{
InitializeComponent();
this.WindowState = FormWindowState.Minimized;
} private void PrintService_Load(object sender, EventArgs e)
{
//初始化是不可见的
//notifyIcon.Visible = false;
} protected override void OnClosing(CancelEventArgs e)
{
if (MessageBox.Show("是否确认关闭打印服务?", "退出确认", MessageBoxButtons.OKCancel) != DialogResult.OK)
{
e.Cancel = true;
}
base.OnClosing(e);
}
消息提示优化
* 参考:http://www.cnblogs.com/ManchesterUnitedFootballClub/p/4596465.html Winfrom 提示消息框公共类
* http://www.cnblogs.com/wuhuacong/archive/2011/11/22/2259128.html Winform开发框架之对话框样式同化
http://www.aichengxu.com/other/1850478.htm DevExpress MessageBox 弹出框 底层类
前台调用:
//图一的前台调用
MessageBox.Show("测试", "标题", MessageBoxButtons.OK);
//图二的前台调用
Functionjsj.ShowMsg("测试", Functionjsj.MsgType.OK);
说明: Functionjsj 为自定义类:下有三种类型的输出:
Functionjsj.ShowMsg(消息, 枚举类型);Functionjsj.ShowMsg(消息, 标题, 枚举类型);Functionjsj.ShowMsgBox(消息, 标题, 枚举类型);
底层类:
#region DevExpress MessageBox 弹出框 #region 枚举弹出类型
public enum MsgType {
/// <summary>
/// 提示
/// </summary>
OK = ,
/// <summary>
/// 警告
/// </summary>
Warning = ,
/// <summary>
/// 询问
/// </summary>
Question = ,
/// <summary>
/// 错误
/// </summary>
Exception = ,
/// <summary>
/// 是/否/取消
/// </summary>
YesNoCancel = ,
/// <summary>
/// 是/否
/// </summary>
YesNo =
}
#endregion /// <summary>
/// 显示消息
/// </summary>
/// <param name="msg">消息</param>
/// <param name="ie">消息类型</param>
/// <returns>需要用户作出选择时,返回YES or NO,否则返回,ok,cancel等</returns>
public static System.Windows.Forms.DialogResult ShowMsg(string msg, MsgType msgType)
{
switch (msgType)
{
case MsgType.OK:
return ShowMsg(msg, "信息", MsgType.OK);
case MsgType.Question:
return ShowMsg(msg, "确认", MsgType.Question);
case MsgType.Warning:
return ShowMsg(msg, "警告", MsgType.Warning);
case MsgType.Exception:
Exception(msg);
return System.Windows.Forms.DialogResult.OK;
case MsgType.YesNoCancel:
return ShowMsg(msg, "请选择", MsgType.YesNoCancel);
case MsgType.YesNo:
return ShowMsg(msg, "请选择", MsgType.YesNo);
default:
return System.Windows.Forms.DialogResult.Cancel;
}
} /// <summary>
/// 显示消息
/// </summary>
/// <param name="msg">消息</param>
/// <param name="caption">标题 系统会自动加上一些信息</param>
/// <param name="msgType">消息类型</param>
/// <returns>需要用户作出选择时,返回YES or NO,否则返回,ok,cancel等</returns>
public static System.Windows.Forms.DialogResult ShowMsg(string msg, string caption, MsgType msgType)
{
switch (msgType)
{
case MsgType.OK:
return ShowMsgBox(msg, caption, msgType);
case MsgType.Question:
return ShowMsgBox(msg, caption, msgType);
case MsgType.Warning:
return ShowMsgBox(msg, caption, msgType);
case MsgType.Exception:
Exception(msg);
return System.Windows.Forms.DialogResult.OK;
case MsgType.YesNoCancel:
return ShowMsgBox(msg, caption, msgType);
case MsgType.YesNo:
return ShowMsgBox(msg, caption, msgType);
default:
return System.Windows.Forms.DialogResult.Cancel;
}
} /// <summary>
/// 显示消息
/// </summary>
/// <param name="msg">消息</param>
/// <param name="catpion">标题</param>
/// <param name="msgType">消息类型</param>
/// <returns>需要用户作出选择时,返回YES or NO,否则返回,ok,cancel等</returns>
public static System.Windows.Forms.DialogResult ShowMsgBox(string msg, string catpion, MsgType msgType)
{
switch (msgType)
{
case MsgType.OK:
return Show(msg, catpion, System.Windows.Forms.MessageBoxButtons.OK);
case MsgType.Question:
return Question(msg, catpion, System.Windows.Forms.MessageBoxButtons.OKCancel, MessageBoxDefaultButton.Button2);
case MsgType.Warning:
return Warning(msg, catpion, System.Windows.Forms.MessageBoxButtons.OK);
case MsgType.Exception:
Exception(msg);
return System.Windows.Forms.DialogResult.OK;
case MsgType.YesNoCancel:
return Information(msg, catpion, System.Windows.Forms.MessageBoxButtons.YesNoCancel, MessageBoxDefaultButton.Button3);
case MsgType.YesNo:
return Information(msg, catpion, System.Windows.Forms.MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2);
default:
return System.Windows.Forms.DialogResult.Cancel;
}
} /// <summary>
/// 显示消息
/// </summary>
/// <param name="msg">消息</param>
/// <param name="ie">消息类型</param>
/// <returns>需要用户作出选择时,返回YES or NO,否则返回,ok,cancel等</returns>
public static System.Windows.Forms.DialogResult ShowMsg(IWin32Window owner, string msg, MsgType msgType)
{
switch (msgType)
{
case MsgType.OK:
return Show(msg, "信息", System.Windows.Forms.MessageBoxButtons.OK);
case MsgType.Question:
return Question(msg, "确认", System.Windows.Forms.MessageBoxButtons.OKCancel, MessageBoxDefaultButton.Button2);
case MsgType.Warning:
return Warning(msg, "警告", System.Windows.Forms.MessageBoxButtons.OK);
case MsgType.Exception:
Exception(msg);
return System.Windows.Forms.DialogResult.OK;
case MsgType.YesNoCancel:
return Information(msg, "请选择", System.Windows.Forms.MessageBoxButtons.YesNoCancel, MessageBoxDefaultButton.Button3);
default:
return System.Windows.Forms.DialogResult.Cancel;
}
} #region Show
public static DialogResult Show(string text)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text);
} public static DialogResult Show(string text, string caption)
{ return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption);
} public static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, buttons, MessageBoxIcon.Information);
} public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(owner, text, caption, buttons, MessageBoxIcon.Information);
} public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, MessageBoxIcon icon)
{ return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, buttons, icon);
} public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, MessageBoxIcon icon)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(owner, text, caption, buttons, icon);
}
#endregion #region Information public static DialogResult Information(string message)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(message, " 消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
} public static DialogResult Information(string message, string caption)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
} public static DialogResult Information(string message, string caption, MessageBoxButtons buttons)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(message, caption, buttons, MessageBoxIcon.Information);
}
public static DialogResult Information(string message, string caption, MessageBoxButtons buttons, MessageBoxDefaultButton defButton)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(message, caption, buttons, MessageBoxIcon.Information, defButton);
}
#endregion #region Question public static DialogResult Question(string text)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, "疑问", MessageBoxButtons.OK, MessageBoxIcon.Question);
}
public static DialogResult Question(string text, string caption)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Question);
}
public static DialogResult Question(string text, string caption, MessageBoxButtons buttons)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, buttons, MessageBoxIcon.Question);
} public static DialogResult Question(string text, string caption, MessageBoxButtons buttons, MessageBoxDefaultButton defButton)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, buttons, MessageBoxIcon.Question, defButton);
} #endregion #region Warning
public static DialogResult Warning(string text)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
public static DialogResult Warning(string text, string caption)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
public static DialogResult Warning(string text, string caption, MessageBoxButtons buttons)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, buttons, MessageBoxIcon.Warning);
}
#endregion #region Exception
public static DialogResult Exception(string text)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public static DialogResult Exception(string text, string caption)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public static DialogResult Exception(string text, string caption, MessageBoxButtons buttons)
{
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, buttons, MessageBoxIcon.Error);
}
#endregion #endregion
winform最小化及关闭提示的更多相关文章
- Winform 基础二 最小化 最大化 关闭 点击任务栏隐藏显示 点击鼠标左键移动窗体
一 最大化 二 最小化 三 关闭 四 点击任务栏隐藏显示 五 点击鼠标左键移动窗体 六 阴影效果鼠标左键移动窗口 #region UI设置 最大化.最小化.关闭.鼠标移动窗口.点击任务栏切换窗口 th ...
- jquery定时滑出可最小化的底部提示层
效果预览:http://keleyi.com/keleyi/phtml/jqtexiao/index.htm当打开页面或者刷新页面后等待两秒钟,会在底部滑出可最小化的提示层.滑出层半透明,可关闭再现. ...
- JS实现漂亮的窗口拖拽效果(可改变大小、最大化、最小化、关闭)
转自<JS实现漂亮的窗口拖拽效果(可改变大小.最大化.最小化.关闭)>:http://www.jb51.net/article/73157.htm 这篇文章主要介绍了JS实现漂亮的窗口 ...
- Delphi模拟最小化恢复关闭按纽
https://yq.aliyun.com/wenji/96083 本文讲的是Delphi模拟最小化恢复关闭按纽, 我们做多文档应用程序开发时,如果在主From中指定mainMenu时,在主菜单上右角 ...
- delphi -----(去掉窗口最大化,最小化、关闭),主窗口,和子窗口之间的设置
一.去掉窗口最大化,最小化.关闭 borderIcons:biSystemMenu:false borderStyle:bsSizeable 二.主子窗口 主main: //调用子窗体procedur ...
- [WinForm]最小化到系统托盘,右键退出
1.拉出一个notifyIcon1到用户界面,也可以NEW一个 2.拉出一个ContextMenuStrip控件,命名为mymenu,集合中增加退出 3.notifyIcon1的属性ContextMe ...
- Winform 最小化双击显示,最小化右键退出。退出
WinForm 之 窗口最小化到托盘及右键图标显示菜单 Form最小化是指整个Form都缩小到任务栏上,但是窗体以Form的标题栏形式显示在任务栏上, 若是想让Form以Icon的形式显示在任务栏右下 ...
- winform最小化及添加右键
private void PrintService_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWind ...
- WinForm最小化到托盘以及托盘右键菜单
首先,先拖一个NotifyIcon到主窗体,然后设置NotifyIcon的图标,不然等下最小化后,都找不到那个程序了,还有那个Text也是,不写名字,就默认是NotifyIcon了..如下图: 然后双 ...
随机推荐
- ES6中的一些新特性
这两个命令是ES6的新语法知识.这两个新的特性解决了ES6中的一些小的"bug"问题.其中包含一些知识:块级作用域.let命令.const命令.全局对象的属性.Google V8引 ...
- Manthan, Codefest 16 A. Ebony and Ivory 水题
A. Ebony and Ivory 题目连接: http://www.codeforces.com/contest/633/problem/A Description Dante is engage ...
- error C2248: 'MyString::pCharArray' : cannot access private member declared in class 'MyString'
std::ostream & operator<<(std::ostream os,const MyString & mystr){os<<mystr.pCha ...
- tomcat配置优化
tomcat服务管理页面 http://192.168.1.249:8080/manager/status 找到下面的内容 "http-nio-8081" (此处端口是根据自己实 ...
- andriod inputType
<EditText Android:layout_width="fill_parent" android:layout_height="wrap_content&q ...
- Pod中访问外部的域名配置
在实际应用中经常遇到Pod中访问外部域名的状况,在Kubenetes 1.6以上的版本通过配置DNS configmap已经解决,详细的内容可以参考官方的 https://kubernetes.io/ ...
- ylbtech-LanguageSamples-NamedAndOptional(命名和可选参数)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-NamedAndOptional(命名和可选参数) 1.A,示例(Sample) 返回顶 ...
- android 启动socket 失败:socket(af_inet sock_stream 0) 返回-1
Android 启动socket 失败:socket(af_inet sock_stream 0) 返回-1 原因权限问题, 应该添加如下权限: <uses-permission android ...
- 如何在Centos7上安装zookeeper 多实例
一.如何在Centos7上安装zookeeper 多实例 cd /usr/local/src/ wget https://mirrors.tuna.tsinghua.edu.cn/apache/zoo ...
- [Python爬虫] 之九:Selenium +phantomjs抓取活动行中会议活动(单线程抓取)
思路是这样的,给一系列关键字:互联网电视:智能电视:数字:影音:家庭娱乐:节目:视听:版权:数据等.在活动行网站搜索页(http://www.huodongxing.com/search?city=% ...