.net - 如何在关闭 xcool 窗口窗体时停止关闭整个应用程序
问题描述
我有一个像 CMS 这样的项目,我正在研究它,我已经添加了一个主题 xcool。
这里有 50 个窗口窗体,但现在的问题是,在关闭一个窗口窗体时,整个应用程序正在关闭。
当我删除这个主题时,它工作得很好。我没有找到任何主题的关闭方法等。
我试过的:
using System.IO;
namespace CampusManagement
{
public partial class Student_Reg : XCoolForm.XCoolForm
private XmlThemeLoader xtl = new XmlThemeLoader();
this.TitleBar.TitleBarBackImage = CampusManagement.Properties.Resources.predator_256x256;
this.MenuIcon = CampusManagement.Properties.Resources.alien_vs_predator_3_48x48.GetThumbnailImage(24, 24, null, IntPtr.Zero);
xtl.ThemeForm = this;
this.Border.BorderStyle = XCoolForm.X3DBorderPrimitive.XBorderStyle.Flat;
this.TitleBar.TitleBarBackImage = CampusManagement.Properties.Resources.Mammooth_1;
this.TitleBar.TitleBarCaption = "Campus Management System";
xtl.ApplyTheme(Path.Combine(Environment.CurrentDirectory, @"..\..\Themes\BlueWinterTheme.xml"));
解决方案
有两种主要方法可以解决此问题。
如果您在事件处理程序
XCoolForm.cs
下查看 XCoolForm 的源代码。OnMouseDown
它在两个地方检查单击的按钮是否是关闭按钮(第 312 行和第 353 行)。如果单击关闭按钮,它将退出应用程序。else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Close) { Application.Exit(); }
你想改为
Application.Exit()
改为Close()
。else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Close) { Close(); }
另一种选择是覆盖 OnMouseDown 事件。但是您需要制作
m_xTitleBar
和PointInRect
保护,以便您可以访问它们。在第 63 行从私有XCoolForm.cs
更改为受保护:m_xTitleBar
protected XTitleBar m_xTitleBar = new XTitleBar();
并
PointInRect
在第 935 行将函数从私有更改为受保护:protected bool PointInRect(Point p, Rectangle rc)
然后在您的表单中,您可以像这样覆盖鼠标按下事件:
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { foreach (XTitleBarButton xbtn in m_xTitleBar.TitleBarButtons) { if (PointInRect( e.Location, new Rectangle( xbtn.XButtonLeft, xbtn.XButtonTop, xbtn.XButtonWidth, xbtn.XButtonHeight ))) { // We just want to check if it was the close button that was clicked, if so then we close this form. if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Close) { Close(); return; } } } // It wasn't the close button that was clicked, so run the base handler and let it take care of the button click. base.OnMouseDown(e); }
推荐阅读
- sql - 如何通过 SQL Server 中的分组列根据日期列的最近 3 个月获取列平均值?
- python - 一种带有numpy的树结构递归算法
- css - ASP.NET Core Angular 中的 Identity Server 4 - 如何共享 css?
- ios - 找不到实现查找函数“class_getMethodImplementation”通过 ObjC 方法分派的步骤将不起作用
- html - 如何在 HTML 中将导航栏中的项目居中?
- css - 平滑收缩,同时减少按钮内的跨度最大宽度
- python - 我的逻辑回归代码有问题
- c# - 使用 C# 在 Zoho 上更新记录
- c# - 编译错误:“意外符号')',预期标识符
- wildfly - WildFly Microprofile 消息与 smallrye