从标题栏 .NET 视觉上删除/禁用关闭按钮 [英] Visually remove/disable close button from title bar .NET

查看:30
本文介绍了从标题栏 .NET 视觉上删除/禁用关闭按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求从我们的 VB .NET 2005 MDI 应用程序中删除或禁用关闭按钮.表单上没有本机属性允许您将关闭按钮灰显,因此用户无法关闭它,而且我不记得在表单类中看到任何允许我这样做的内容.

I have been asked to remove or disable the close button from our VB .NET 2005 MDI application. There are no native properties on a form that allow you to grey out the close button so the user cannot close it, and I do not remember seeing anything in the form class that will allow me to do this.

在 .NET 2005 或更高版本中是否有 API 调用或一些神奇的属性要设置或函数要调用来执行此操作?

Is there perhaps an API call or some magical property to set or function to call in .NET 2005 or later to do this?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

更多信息:

我需要维护最小化/最大化功能

I need to maintain the minimize/maximize functionality

我需要保持原来的标题栏,因为表单的绘制方法已经很复杂了.

I need to maintain the original title bar because the form's drawing methods are already very complex.

推荐答案

根据您添加到问题中的最新信息,跳到我的答案的末尾.

Based on the latest information you added to your question, skip to the end of my answer.

这是您需要设置为 false 的内容:Form.ControlBox 属性

This is what you need to set to false: Form.ControlBox Property

但是,您将丢失最小化和最大化按钮以及应用程序菜单(左上角).

BUT, you will lose the minimize and maximize buttons as well as the application menu (top left).

作为替代方法,覆盖 OnClose 并将取消设置为 true(C# 示例):

As an alternative, override OnClose and set Cancel to true (C# example):

protected override void OnFormClosing(FormClosingEventArgs e)
{
    if (e.CloseReason != CloseReason.WindowsShutDown && e.CloseReason != CloseReason.ApplicationExitCall)
    {
        e.Cancel = true;
    }

    base.OnFormClosing(e);
}

<小时>

如果这些解决方案都不可接受,并且您必须仅禁用关闭按钮,则可以使用 pinvoke/createparams 路线:


If neither of these solutions are acceptable, and you must disable just the close button, you can go the pinvoke/createparams route:

如何使用 .NET 应用程序禁用窗口表单中的关闭按钮

这是jdm代码的VB版本:

This is the VB version of jdm's code:

Private Const CP_NOCLOSE_BUTTON As Integer = &H200
Protected Overloads Overrides ReadOnly Property CreateParams() As    CreateParams
   Get 
      Dim myCp As CreateParams = MyBase.CreateParams 
      myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON 
      Return myCp 
   End Get 
End Property 

这篇关于从标题栏 .NET 视觉上删除/禁用关闭按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆