Winform 弹出错误对话框的问题...

sunlovesea 2008-10-13 04:53:19
我想实现的功能是遇到异常时弹出错误提示对话框:窗口中显示三个按钮【确定】【取消】【详情】
点击详情在错误窗口中显示错误的详细信息....
在Winform中如何实现?
...全文
863 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
peiran001 2009-03-13
  • 打赏
  • 举报
回复
微软自带的MessageBox,没有你说的那个扩展功能,可以自己写,使用一个对话框即可
marvelstack 2008-10-13
  • 打赏
  • 举报
回复
两种方式,简单的可以通过MessageBox类来实现,
如果需要更灵活的控制建议楼主自己写一个Form窗体继承类进行解决。

另外给楼主一个扑获全局异常事件的代码例子。

=====================================
使用全局事件扑捉
=====================================
using System;
using System.Windows.Forms;
//using Microsoft.Win32;

//注册全局的异常处理程序,扑获产生的异常。
namespace Zhengzuo.CSharpCode
{
static class Program
{

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[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.");
}
}
}

killer_liqiao 2008-10-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 copico 的回复:]
MessageBox.Show("客户不能为空!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
[/Quote].
HJun_www 2008-10-13
  • 打赏
  • 举报
回复
收回我的想法,很傻很天真
HJun_www 2008-10-13
  • 打赏
  • 举报
回复
继承 MessageBox 类改个Button的Text
mjjzg 2008-10-13
  • 打赏
  • 举报
回复
【确定】【取消】【详情】????
那用MessageBox.Show()还无法实现,
还是再写个form页面吧
palmax 2008-10-13
  • 打赏
  • 举报
回复
简单点,自己写个Form,放三个按钮上去就行了

复杂点,设置WH_CBT钩子,对MessageBox的WndProc自己处理
yilanwuyu123 2008-10-13
  • 打赏
  • 举报
回复
自己写Form实现。
pp_shy 2008-10-13
  • 打赏
  • 举报
回复
自己定义个Form来实现吧
h_w_king 2008-10-13
  • 打赏
  • 举报
回复
直接用 MessageBox.Show 只能有系统定义的一些按钮,(MessageBoxButtons.YesNoCancel等)
如果要显示三个按钮【确定】【取消】【详情】 自己写个Form 就是了.
copico 2008-10-13
  • 打赏
  • 举报
回复
MessageBoxButtons后面可以自己选择
copico 2008-10-13
  • 打赏
  • 举报
回复
MessageBox.Show("客户不能为空!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧