Click here to Skip to main content
13,861,486 members
Click here to Skip to main content
Add your own
alternative version


83 bookmarked
Posted 26 Jul 2005
Licenced GPL3

Move window/form without Titlebar in C#

, 26 Jul 2005
Rate this:
Please Sign up or sign in to vote.
How to move a form without having a Titlebar in C#.


This is my first article and I hope my English is OK. Have you ever wanted to move a window without a Titlebar in C#? Well, then you're right here.

Let's start

First you have to add the following code in the header of your project. This is needed to load the required DLL's to our project. According to MSDN ReleaseCapture: removes mouse capture from the object in the current document and SendMessage: sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.

using System.Runtime.InteropServices;

If you've done this, you can add the const and the DLL functions:

public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

public static extern int SendMessage(IntPtr hWnd, 
                 int Msg, int wParam, int lParam);
public static extern bool ReleaseCapture();

Then put the following two lines of code in the form's MouseDown event like this:

private void Form1_MouseDown(object sender, 
        System.Windows.Forms.MouseEventArgs e)
    if (e.Button == MouseButtons.Left)
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);

Believe it or not - you've done it! Now run the App and try to move the form by clicking on the form and moving the mouse (you have to hold the button pressed!)

Hope you find it useful. Enjoy!

Thanks to Patric_J and John Wood for their replies! The code has been updated!


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Germany Germany
Born on August 6th 1982 in Neuss (NRW in Germany). Currently i'm 22 years old guy and my Hobby's are programming, bicycle and swim.

You may also be interested in...


Comments and Discussions

SuggestionHandle does not exists ... in my case.. Pin
Taeho Kim15-May-18 7:13
memberTaeho Kim15-May-18 7:13 
QuestionThx Pin
Member 136107637-Jan-18 4:00
memberMember 136107637-Jan-18 4:00 
QuestionMy vote 5 Pin
Tien N19-Aug-17 7:43
memberTien N19-Aug-17 7:43 
GeneralMy vote of 5 Pin
Dennis Fazekas8-Apr-17 8:57
memberDennis Fazekas8-Apr-17 8:57 
AnswerFor the people who copy paste Pin
Member 1301397920-Feb-17 22:54
memberMember 1301397920-Feb-17 22:54 
PraiseThank You! Pin
KIkapel29-Jul-16 23:31
memberKIkapel29-Jul-16 23:31 
GeneralMy vote of 5 Pin
mochoutian21-Oct-14 17:05
membermochoutian21-Oct-14 17:05 
SuggestionAdd DragDetect() Pin
KevinSW31-Jul-14 21:57
memberKevinSW31-Jul-14 21:57 
GeneralMy Vote of 5 Pin
faysal_ubit27-Jun-14 21:55
memberfaysal_ubit27-Jun-14 21:55 
QuestionMessage Closed Pin
26-Sep-13 0:23
memberMember 1023224426-Sep-13 0:23 
GeneralAlso works with single objects inside the form! Pin
J&Geckos24-Feb-13 11:07
memberJ&Geckos24-Feb-13 11:07 
GeneralMy vote of 5 Pin
J&Geckos24-Feb-13 11:04
memberJ&Geckos24-Feb-13 11:04 
QuestionC# Show Hide Windows Forms Pin
Tishantha18-Jan-13 5:41
memberTishantha18-Jan-13 5:41 
GeneralMy vote of 1000000000000000 Pin
Oraion13-Jan-13 16:12
memberOraion13-Jan-13 16:12 
GeneralMy vote of 5 Pin
Sushant Shidore28-Oct-12 22:53
memberSushant Shidore28-Oct-12 22:53 
QuestionHi... Pin
nileshbahirshet9-May-12 20:56
membernileshbahirshet9-May-12 20:56 
AnswerRe: Hi... Pin
FreewareFire10-May-12 11:19
memberFreewareFire10-May-12 11:19 
GeneralMy vote of 5 Pin
Neoshao23-Dec-11 5:52
memberNeoshao23-Dec-11 5:52 
GeneralMy vote of 3 Pin
LimitedAtonement19-Nov-11 15:12
memberLimitedAtonement19-Nov-11 15:12 
GeneralRe: My vote of 3 Pin
Nitesh Luharuka9-Jan-14 4:55
professionalNitesh Luharuka9-Jan-14 4:55 
GeneralMy vote of 5 Pin
Horia Tudosie6-Oct-11 3:33
memberHoria Tudosie6-Oct-11 3:33 
QuestionSlick! Short and to the point. Pin
AVIDeveloper27-Jun-11 7:17
memberAVIDeveloper27-Jun-11 7:17 
GeneralDragmove Pin
stage616-May-11 7:02
memberstage616-May-11 7:02 
GeneralMy vote of 5 Pin
deep124519-Feb-11 2:37
memberdeep124519-Feb-11 2:37 
GeneralMy vote of 5 Pin
shanawazway23-Jan-11 20:21
membershanawazway23-Jan-11 20:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190214.1 | Last Updated 26 Jul 2005
Article Copyright 2005 by FreewareFire
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid