Remove the title bar in Windows Forms

前端 未结 7 1962
孤城傲影
孤城傲影 2020-11-29 20:10

How can I remove the blue border that\'s on top of the Window Form? (I don\'t know the name of it exactly.)

相关标签:
7条回答
  • 2020-11-29 20:40

    You can set the Property FormBorderStyle to none in the designer, or in code:

    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    
    0 讨论(0)
  • 2020-11-29 20:50

    if by Blue Border thats on top of the Window Form you mean titlebar, set Forms ControlBox property to false and Text property to empty string ("").

    here's a snippet:

    this.ControlBox = false;
    this.Text = String.Empty;
    
    0 讨论(0)
  • 2020-11-29 20:51

    Also add this bit of code to your form to allow it to be draggable still.

    Just add it right before the constructor (the method that calls InitializeComponent()


    private const int WM_NCHITTEST = 0x84;
    private const int HTCLIENT = 0x1;
    private const int HTCAPTION = 0x2;
    
    ///
    /// Handling the window messages
    ///
    protected override void WndProc(ref Message message)
    {
        base.WndProc(ref message);
    
        if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
            message.Result = (IntPtr)HTCAPTION;
    }
    

    That code is from: https://jachman.wordpress.com/2006/06/08/enhanced-drag-and-move-winforms-without-having-a-titlebar/

    Now to get rid of the title bar but still have a border combine the code from the other response:

    this.ControlBox = false;

    this.Text = String.Empty;

    with this line:

    this.FormBorderStyle = FormBorderStyle.FixedSingle;


    Put those 3 lines of code into the form's OnLoad event and you should have a nice 'floating' form that is draggable with a thin border (use FormBorderStyle.None if you want no border).

    0 讨论(0)
  • 2020-11-29 20:51

    Set FormsBorderStyle of the Form to None.

    If you do, it's up to you how to implement the dragging and closing functionality of the window.

    0 讨论(0)
  • 2020-11-29 20:57
     Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    
    0 讨论(0)
  • 2020-11-29 20:58

    enter image description here

    0 讨论(0)
提交回复
热议问题