【问题标题】:Winform, custom title bar with Image and text but no control buttons?Winform,带有图像和文本但没有控制按钮的自定义标题栏?
【发布时间】:2011-08-16 06:31:47
【问题描述】:

在 winform 应用程序中,如何在“标题栏”中添加图像和标题文本并删除所有控制按钮(最小、最大和关闭)。我可以显示图像和标题文本,但无法删除所有按钮,包括“关闭”按钮。有什么解决方法吗?

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    您可以将表单的 ControlBox 属性设置为 False,然后您可以轻松删除所有按钮(最小、最大、关闭按钮),甚至可以将 Title 和 Image 设置为它,而使用 FormBorderStyle 它将完全删除标题栏,这对您的问题没有帮助。

    所以我建议你设置
    ControlBox=false的形式

    【讨论】:

      【解决方案2】:

      在 FormDesigner 中将 FormBorderStyle 设置为 None 可能会有所帮助。

      【讨论】:

        【解决方案3】:

        不幸的是,您需要使用 PInvoke 调用 Windows API 函数。

          // Changes an attribute of the specified window.          
          [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
          public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
          // Retrieves information about the specified window.        
          [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
          public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
          public const int GWL_STYLE = (-16);
          public const int WS_SYSMENU = 0x00080000;
          public const int WS_MAXIMIZEBOX = 0x00010000;
        
        
          public static void SetDialogStyle(Form window)
            {
                // We disable the control box functionality for the window
                // i.e. remove the minimize, maximize and close button as 
                // well as the system menu.
        
                int style = GetWindowLong(window.Handle, GWL_STYLE);
                style &= ~(WS_SYSMENU | WS_MAXIMIZEBOX);
                SetWindowLong(window.Handle, GWL_STYLE, style);
            }
        

        你可以在 OnLoad 事件中调用这个函数,传递 this 作为函数的参数。

        【讨论】:

        • 在 from1.cs 中我在哪里调用这个方法?
        • WindowInteropHelper ??找不到?
        • 但此代码也删除了标题图标,但应该显示图标....!!如何做到这一点?
        • Dhana 你需要使用 windows 样式 msdn.microsoft.com/en-us/library/ms632600(v=vs.85).aspx 在 Style 变量中添加或删除它们
        猜你喜欢
        • 1970-01-01
        • 2010-12-21
        • 1970-01-01
        • 2015-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-14
        • 1970-01-01
        相关资源
        最近更新 更多