asp.net core_asp.net winform(C#)弹出对话框实现代码

时间:2018-02-06  来源:WinForm  阅读:

//消息框中需要显示哪些按钮,此处显示“确定”和“取消”

 代码如下  MessageBoxButtons messButton = MessageBoxButtons.OKCancel;

 

//"确定要退出吗?"是对话框的显示信息,"退出系统"是对话框的标题

 //默认情况下,如MessageBox.Show("确定要退出吗?")只显示一个“确定”按钮。
 DialogResult dr = MessageBox.Show("确定要退出吗?", "退出系统", messButton);

 

 代码如下

if (dr == DialogResult.OK) //如果点击“确定”按钮

 {

   ……

 }

else //如果点击“取消”按钮

{

  ……

}

 

MessageBoxButtons指定若干常数,用以定义MessageBox上将显示哪些按钮(来自MSDN)

MessageBoxButtons成员:

成员名称                                  说明

AbortRetryIgnore 消息框包含“中止”、“重试”和“忽略”按钮。

OK                                  消息框包含“确定”按钮。(默认)
OKCancel                      消息框包含“确定”和“取消”按钮。(上例所示)
RetryCancel      消息框包含“重试”和“取消”按钮。

YesNo                       消息框包含“是”和“否”按钮。
YesNoCancel          消息框包含“是”、“否”和“取消”按钮


实现的功能是遇到异常时弹出错误提示对话框:窗口中显示三个按钮【确定】【取消】【详情】

 代码如下

=====================================
使用全局事件扑捉
=====================================
using System;
using System.Windows.Forms;
//using Microsoft.Win32;
 
//注册全局的异常处理程序,扑获产生的异常。
namespace Zhengzuo.CSharpCode
{
    static class Program
    {
        
        ///


        /// 应用程序的主入口点。
        ///

        [STAThread]
        static void Main()
        { 
            if ( false == SingleInstance.HandleRunningInstance() )
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
 
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FormMain());
            }
        }
 
        //static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
        //{
        //    throw new Exception("The method or operation is not implemented.");
        //}
 
        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            throw new Exception("The method or operation is not implemented.");
        }
 
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}


winform,c#弹出错误提示框,带红叉的弹出窗口,MessageBox.Show

解决办法

1.MessageBox.Show("两次重复密码不一致", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); 

asp.net core_asp.net winform(C#)弹出对话框实现代码

http://m.bbyears.com/asp/39067.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新