.NET hide titlebar but keep border

前端 未结 3 1165
深忆病人
深忆病人 2021-01-02 18:37

I was wondering how to hide the titlebar of a form but keep the original border, like e.g Dropbox does:

Thanks in advance!

相关标签:
3条回答
  • 2021-01-02 19:05

    Here is a simple way:

    this.ControlBox = false;
    this.Text = string.Empty;
    

    If the Form is designed to be a pop-up dialog, you might want to add the following line:

    this.ShowInTaskBar = false;
    

    That keeps the Form from appearing in the taskbar.

    0 讨论(0)
  • 2021-01-02 19:12
    // 3rd option (C#)
    protected override CreateParams CreateParams
    {
        get
        {
            int WS_DLGFRAME = 0x400000;
            CreateParams result = base.CreateParams;
            result.Style &= ~WS_DLGFRAME;
            return result;
        }
    }
    
    0 讨论(0)
  • 2021-01-02 19:21

    Set FormBorderStyle to FormBorderStyle.Sizable or FormBorderStyle.SizableToolWindow and set Text to an empty string, and ControlBox to false

    Note that FixedToolWindow won't work, it will remove the border. If you don't want it to be sizable, use SizableToolWindow and add this to the form's codebehind (adding both languages since you don't specify and tagged the question with both):

    In vb.net:

    Protected Overrides Sub WndProc(ByRef message As Message)               
        If message.Msg = &H84 Then ' WM_NCHITTEST
            message.Result = CType(1, IntPtr)
            Return
        End If    
        MyBase.WndProc(message)
    End Sub
    

    In C#:

    protected override void WndProc(ref Message message)
    {
        if (message.Msg == 0x0084) // WM_NCHITTEST
            message.Result = (IntPtr)1;   
        else base.WndProc(ref message);
    }
    
    0 讨论(0)
提交回复
热议问题