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了..如下图: 然后双 ...
随机推荐
- Java程序运行时内存划分
1.Java程序跨平台运行的原因 主要原因是:各种平台的JVM和字节码文件 Java源程序--具体平台的机器代码文件---被编译器翻译成平台无关的Class文件,又用特定JVM运行字节码文件,JVM在 ...
- LookupError: unknown encoding: cp65001
在CMD下解释运行python时出现LookupError: unknown encoding: cp65001错误(编码错误) 在cmd下chcp命令(大概是change codepage?)可查看 ...
- 转-"进程android.process.acore已意外停止" 解决办法
运行手机虚拟机时,老是弹出这样的“android.process.acore“服务已意外停止,虽不影响正常使用,但终究影响心情.网上找的方案,按如下步骤操作,可以解决问题: 出现这个提示不用担心,并不 ...
- JAVA常见算法题(三十)
package com.forezp.util; import java.io.BufferedReader; import java.io.FileReader; import java.io.In ...
- 性能工具TProfiler介绍文档
工具介绍 TProfiler是一个可以在生产环境长期使用的性能分析工具.它同时支持剖析和采样两种方式,记录方法执行的时间和次数,生成方法热点 对象创建热点 线程状态分析等数据,为查找系统性能瓶颈提供数 ...
- Walle代码发布系统
Walle 一个web部署系统工具,配置简单.功能完善.界面流畅.开箱即用!支持git.svn版本管理,支持各种web代码发布,PHP,Python,JAVA等代码的发布.回滚,可以通过web来一键完 ...
- Git系列二之数据管理
1.Git基本管理 git常用的基本操作 1.1提交数据 我们可以简单的把工作目录理解成是一个被Git服务程序管理的目录,Git会时刻的追踪目录内文件的改动,另外在安装好了Git服务程序后,默认就会创 ...
- OSG 中文解决方案 【转】
概述 本文只限于 windows 环境下. OSG 在 windows 下对中文支持已经非常的好了,但是可能很多人并不知道如何去正确的使用.为了解决这些常见的问题,还有一些基础知识的普及.特此把 OS ...
- 11g R2单实例手工建库
官档地址:Administrator's Guide --->>>Creating and Configuring an Oracle Database--->>> ...
- CocoSourcesCS 2
CocoSourcesCS 2 /*------------------------------------------------------------------------- DFA.cs - ...