C# Moveable non-border window

If you wanna have your own window design for your program, you probably wanna get rid of the windows border with the minimize and close buttons. But then you ask yourself, how you want to move it around the screen? You realize you cant drag the window anymore. So how are we going to fix this? Then you just need a Moveable non-border window!

The answer to this question is very simple:

  1. You need to define

    as integers.

  2. You need to define

    as boolean.

  3. You need a MouseDown event for the element you want to move your window with, in this case I am using the main panel. This MouseDown event sets

    to true.

  4. Next you need a MouseMove event which looks like this:
  5. if (mouseDown)
            mouseX = MousePosition.X -200; // This way we have the mouse closer to the middle of the window
            mouseY = MousePosition.Y - 40;
            this.SetDesktopLocation(mouseX, mouseY);

  6. And at the end you need a MouseUp event to exit the MouseMove event, containing
    mouseDown = false;

So I hope this was a helpful post for you. Please respond with a comment if you liked it!

3 Replies to “C# Moveable non-border window”

  1. I like the helpful info you provide in your articles.
    I’ll bookmark your weblog and check again here regularly.
    I am quite sure I will learn a lot of new stuff right here!
    Best of luck for the next!

Leave a Reply

Your email address will not be published. Required fields are marked *