Click here to Skip to main content
11,789,706 members (59,826 online)
Click here to Skip to main content

Move window/form without Titlebar in C#

, 26 Jul 2005 GPL3 248.8K 4.6K 80
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

GeneralMy vote of 5 Pin
mochoutian21-Oct-14 16:05
membermochoutian21-Oct-14 16:05 
SuggestionAdd DragDetect() Pin
KevinSW31-Jul-14 20:57
memberKevinSW31-Jul-14 20:57 
GeneralMy Vote of 5 Pin
faysal_ubit27-Jun-14 20:55
memberfaysal_ubit27-Jun-14 20:55 
QuestionMessage Automatically Removed Pin
25-Sep-13 23:23
memberMember 1023224425-Sep-13 23:23 
GeneralAlso works with single objects inside the form! Pin
J&Geckos24-Feb-13 10:07
memberJ&Geckos24-Feb-13 10:07 
GeneralMy vote of 5 Pin
J&Geckos24-Feb-13 10:04
memberJ&Geckos24-Feb-13 10:04 
QuestionC# Show Hide Windows Forms Pin
Tishantha18-Jan-13 4:41
memberTishantha18-Jan-13 4:41 
GeneralMy vote of 1000000000000000 Pin
Oraion13-Jan-13 15:12
memberOraion13-Jan-13 15:12 
GeneralMy vote of 5 Pin
Sushant Shidore28-Oct-12 21:53
memberSushant Shidore28-Oct-12 21:53 
QuestionHi... Pin
nileshbahirshet9-May-12 19:56
membernileshbahirshet9-May-12 19:56 
AnswerRe: Hi... Pin
FreewareFire10-May-12 10:19
memberFreewareFire10-May-12 10:19 
GeneralMy vote of 5 Pin
Neoshao23-Dec-11 4:52
memberNeoshao23-Dec-11 4:52 
GeneralMy vote of 3 Pin
LimitedAtonement19-Nov-11 14:12
memberLimitedAtonement19-Nov-11 14:12 
GeneralRe: My vote of 3 Pin
Nitesh Luharuka9-Jan-14 3:55
memberNitesh Luharuka9-Jan-14 3:55 
GeneralMy vote of 5 Pin
Horia Tudosie6-Oct-11 2:33
memberHoria Tudosie6-Oct-11 2:33 
QuestionSlick! Short and to the point. Pin
Avi Bueno27-Jun-11 6:17
memberAvi Bueno27-Jun-11 6:17 
GeneralDragmove Pin
stage616-May-11 6:02
memberstage616-May-11 6:02 
GeneralMy vote of 5 Pin
deep124519-Feb-11 1:37
memberdeep124519-Feb-11 1:37 
GeneralMy vote of 5 Pin
shanawazway23-Jan-11 19:21
membershanawazway23-Jan-11 19:21 
GeneralSlight modification for WPF :) Pin
xhutchinson17-Jan-11 18:45
memberxhutchinson17-Jan-11 18:45 
GeneralRe: Slight modification for WPF :) Pin
AhmyAM10-Feb-14 5:18
memberAhmyAM10-Feb-14 5:18 
GeneralMy vote of 5 Pin
jingobaba30-Dec-10 1:32
memberjingobaba30-Dec-10 1:32 
GeneralMy vote of 5 Pin
Francisco Soto23-Jul-10 15:01
memberFrancisco Soto23-Jul-10 15:01 
GeneralDirectShow + WM_NCLBUTTONDOWN Pin
SolarAngel5-Mar-10 14:01
memberSolarAngel5-Mar-10 14:01 
GeneralRight Mouse Button Pin
ddboarm18-Dec-09 8:06
memberddboarm18-Dec-09 8:06 
GeneralRe: Right Mouse Button Pin
LimitedAtonement19-Nov-11 14:11
memberLimitedAtonement19-Nov-11 14:11 
GeneralGreat Pin
MrKhal28-Nov-09 2:36
memberMrKhal28-Nov-09 2:36 
Generalgreat but Pin
Antoun Gorgy28-Nov-09 0:08
memberAntoun Gorgy28-Nov-09 0:08 
NewsReviews [modified] Pin
GoS-ExiGo5-Aug-09 4:25
memberGoS-ExiGo5-Aug-09 4:25 
Questionthank's for you greate article ! Pin
RNematjon30-Jul-09 1:00
memberRNematjon30-Jul-09 1:00 
Generalthanks champ Pin
Jethro874-Jun-09 8:35
memberJethro874-Jun-09 8:35 
GeneralGreat! Pin
emboole4-Jun-09 3:03
memberemboole4-Jun-09 3:03 
GeneralVery thank you. Pin
V# Guy2-Jun-09 17:07
memberV# Guy2-Jun-09 17:07 
GeneralThanks!!! Pin
RazorHaven20-May-09 7:31
memberRazorHaven20-May-09 7:31 
GeneralThanks much Pin
kennygmaina4-Feb-09 23:03
memberkennygmaina4-Feb-09 23:03 
GeneralBaaaaaaam! Pin
idrivefastlane19-Jan-09 22:08
memberidrivefastlane19-Jan-09 22:08 
Generalmove to next form Pin
kanza azhar4-Jun-08 11:58
memberkanza azhar4-Jun-08 11:58 
GeneralRe: move to next form Pin
kanza azhar4-Jun-08 12:02
memberkanza azhar4-Jun-08 12:02 
GeneralSmart code, thanks! Pin
Member 183173730-Mar-08 7:29
memberMember 183173730-Mar-08 7:29 
GeneralGr8 Pin
vachan18-Sep-07 23:14
membervachan18-Sep-07 23:14 
GeneralNot in mouse down event Pin
AlexanderBraun5-Jan-06 4:20
memberAlexanderBraun5-Jan-06 4:20 
AnswerRe: Not in mouse down event Pin
FreewareFire8-Jan-06 11:33
memberFreewareFire8-Jan-06 11:33 
QuestionRe: Not in mouse down event Pin
AJafer6-Sep-07 2:19
memberAJafer6-Sep-07 2:19 
QuestionRe: Not in mouse down event Pin
jury_mart19-May-08 23:01
memberjury_mart19-May-08 23:01 
QuestionRe: Not in mouse down event Pin
craigk8-Apr-09 8:12
membercraigk8-Apr-09 8:12 
GeneralRe: Not in mouse down event Pin
Nitesh Luharuka9-Jan-14 4:12
memberNitesh Luharuka9-Jan-14 4:12 
Generalmove other window Pin
Kaczy19-Dec-05 12:38
memberKaczy19-Dec-05 12:38 
AnswerRe: move other window Pin
FreewareFire8-Jan-06 11:32
memberFreewareFire8-Jan-06 11:32 
GeneralAnother method & Extending the article Pin
JockerSoft3-Aug-05 21:10
memberJockerSoft3-Aug-05 21:10 
GeneralRe: Another method & Extending the article Pin
FreewareFire7-Sep-05 2:59
memberFreewareFire7-Sep-05 2:59 

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

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

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