Search code examples
c#winformswindowdockform-control

How to dock a windows form in C#?


I just would like to know if it is possible to dock a windows form on top of the user screen? I have been trying to do this by manually setting the position of my form to the coordinates I want. But using this method, however, allows the user to change the position of the form just by dragging it. I want to make the form docked to the upper portion of the screen since this window form will server as a menu for the project I am making.

Thanks a lot. :)


Solution

  • So after some tweaks I finally was able to get this code working.

    this.DesktopLocation = new Point((Screen.PrimaryScreen.Bounds.Width / 2 - 420), 0);
    

    I placed that line below the InitializeComponent() and it docks my form to the center of the screen with whatever resolution values.