我有一个像 CMS 这样的项目,我正在开发它,并且我添加了一个主题 xcool。
这里有 50 个窗口窗体,但现在的问题是,在关闭一个窗口窗体时,整个应用程序都会关闭。
当我删除这个主题时,它工作得很好。没有找到Theme等的关闭方法
我尝试过的:
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 的源代码,请查看
XCoolForm.cs
中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
以便您可以访问它们。在XCoolForm.cs
中,将第 63 行的m_xTitleBar
从私有(private)更改为 protected :protected XTitleBar m_xTitleBar = new XTitleBar();
并在第 935 行将
PointInRect
函数从私有(private)更改为 protected :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); }
关于.net - 如何在关闭 xcool 窗口窗体时停止关闭整个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52178868/