473,324 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to move a borderless windows form in c#.NET

Hi,
Can anybody help me in solving this problem. I m developing an
application in which the main application form is borderless. now i m
not able to move the application form with the help of mouse.
Thanks,

Nov 17 '05 #1
6 15059
Hi Nikki,

In Your case you've got to handle MouseMove events of the
main form. Check if left-button is pressed and the change
the form location according to previous point (e.X, e.Y) of
handled event.

HTH
Marcin
Hi,
Can anybody help me in solving this problem. I m developing an
application in which the main application form is borderless. now i m
not able to move the application form with the help of mouse.
Thanks,

Nov 17 '05 #2
Hi,

In addition to what Marcin has said, another solution is to handle the
WM_NCHITTEST message and return HTCAPTION if the form must be dragged. If
you add the following code to your Form, the form will be dragged when you
click on the client area and drag your mouse.

const int WM_NCHITTEST = 0x0084;
const int HTCAPTION = 2;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCHITTEST)
{
Point pt = this.PointToClient(new Point(m.LParam.ToInt32()));
if (ClientRectangle.Contains(pt))
{
m.Result = new IntPtr(HTCAPTION);
return;
}
}

base.WndProc (ref m);
}

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor

"Nikki" <ap*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,
Can anybody help me in solving this problem. I m developing an
application in which the main application form is borderless. now i m
not able to move the application form with the help of mouse.
Thanks,

Nov 17 '05 #3
Is this the only way to respond to messages sent to a form? meaning having
to override the WndProc.

I've done Delphi development for quite a while now and in Delphi you can
bind a message to a method and the method would be called for you
automagiclly when the message was received. This prevented you from having
to have a giant case statement for each message you wanted to handle.

--
Thanks
Wayne Sepega
Jacksonville, Fl

Enterprise Library Configuration Console Module Generator
http://workspaces.gotdotnet.com/elccmg

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:Ok**************@TK2MSFTNGP14.phx.gbl...
Hi,

In addition to what Marcin has said, another solution is to handle the
WM_NCHITTEST message and return HTCAPTION if the form must be dragged. If
you add the following code to your Form, the form will be dragged when you
click on the client area and drag your mouse.

const int WM_NCHITTEST = 0x0084;
const int HTCAPTION = 2;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCHITTEST)
{
Point pt = this.PointToClient(new Point(m.LParam.ToInt32()));
if (ClientRectangle.Contains(pt))
{
m.Result = new IntPtr(HTCAPTION);
return;
}
}

base.WndProc (ref m);
}

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor

"Nikki" <ap*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,
Can anybody help me in solving this problem. I m developing an
application in which the main application form is borderless. now i m
not able to move the application form with the help of mouse.
Thanks,


Nov 17 '05 #4
Hi,

I've got some code for your main Form.

Cheers!
Marcin

<code>
private Point downLocation;
private Point downMousePosition;
private bool isMouseDown=false;

protected override void OnMouseMove(MouseEventArgs e) {
lock(this) {
if( e.Button==MouseButtons.Left ) {
if( isMouseDown ) {
Point mousePos=Form.MousePosition;
Point location=downLocation;
location.X=location.X +
(mousePos.X-downMousePosition.X);
location.Y=location.Y +
(mousePos.Y-downMousePosition.Y);
base.Location=location;
}
else {
downLocation=base.Location;
downMousePosition=Form.MousePosition;
isMouseDown=true;
}
}
else {
isMouseDown=false;
}

base.OnMouseMove(e);
}
}

</code>
Hi Nikki,

In Your case you've got to handle MouseMove events of the
main form. Check if left-button is pressed and the change
the form location according to previous point (e.X, e.Y) of
handled event.

HTH
Marcin
Hi,
Can anybody help me in solving this problem. I m developing an
application in which the main application form is borderless. now i m
not able to move the application form with the help of mouse. Thanks,

Nov 17 '05 #5
Joe
Could also use the API directly:

private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HTCAPTION = 0x2;

[ DllImport( "user32.dll" ) ]
public static extern bool ReleaseCapture();

[ DllImport( "user32.dll" ) ]
public static extern int SendMessage( IntPtr hWnd, int Msg, int wParam, int
lParam );

public static void MoveForm( IntPtr Handle )
{
ReleaseCapture();
int Status = SendMessage( Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
....

Then call this MoveForm function however you'd want to trigger the form
moving, say by clicking and holding on a different control:

private void TitleBar_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
//simulate clicking on windows standard title bar
if (e.Button == MouseButtons.Left) MoveForm(this.Handle);
}

"Nikki" wrote:
Hi,
Can anybody help me in solving this problem. I m developing an
application in which the main application form is borderless. now i m
not able to move the application form with the help of mouse.
Thanks,

Nov 17 '05 #6
Hi Wayne,

..NET does not support a method binding mechanism like that of Delphi for
windows messages.
In defence of C# had they included such a mechanism this would tightly tie
the language to the Windows platform.

Of course before going this route you should always make sure that there is
not an existing event that corresponds to the underlying message.
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Wayne" <Me******@community.nospam> wrote in message
news:##**************@TK2MSFTNGP14.phx.gbl...
Is this the only way to respond to messages sent to a form? meaning having
to override the WndProc.

I've done Delphi development for quite a while now and in Delphi you can
bind a message to a method and the method would be called for you
automagiclly when the message was received. This prevented you from having
to have a giant case statement for each message you wanted to handle.

--
Thanks
Wayne Sepega
Jacksonville, Fl

Enterprise Library Configuration Console Module Generator
http://workspaces.gotdotnet.com/elccmg

"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:Ok**************@TK2MSFTNGP14.phx.gbl...
Hi,

In addition to what Marcin has said, another solution is to handle the
WM_NCHITTEST message and return HTCAPTION if the form must be dragged. If you add the following code to your Form, the form will be dragged when you click on the client area and drag your mouse.

const int WM_NCHITTEST = 0x0084;
const int HTCAPTION = 2;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCHITTEST)
{
Point pt = this.PointToClient(new Point(m.LParam.ToInt32()));
if (ClientRectangle.Contains(pt))
{
m.Result = new IntPtr(HTCAPTION);
return;
}
}

base.WndProc (ref m);
}

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor

"Nikki" <ap*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,
Can anybody help me in solving this problem. I m developing an
application in which the main application form is borderless. now i m
not able to move the application form with the help of mouse.
Thanks,



Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan | last post by:
i really need to create a window/dialog that just contains a bitmap and nothing else - no window frame, caption or buttons, or any sign of a grey background. so far ive only managed to get rid of...
1
by: Cc | last post by:
hi , i try this code to move form but the form flick when ever I move the move. Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles...
3
by: Boki | last post by:
Dear All, How to move a form that FormBorderStyle is None? I want to use mouse drag method.. Best reagrds, Boki.
3
by: Liz | last post by:
I need to implement dragging a borderless form by clicking/dragging on the form surface. Using the "standard" approach (setting "CanMove" flag on MouseDown, moving the form by the delta of the...
4
by: David Gouge | last post by:
Hi All, I have a borderless form that i can drag around fine when dragging anywhere on the form by using the following code: protected override void WndProc(ref Message m) { const int...
1
by: SeanR | last post by:
Hi, I wasn't happy with the customisability of the standard Windows form, so I decided to implement my own. Basically what I did was extend a borderless form and add my own borders and caption...
8
by: James Arnold | last post by:
I currently have a borderless form, which I am subclassing to allow dragging & dropping: Protected Overrides Sub WndProc(ByRef m As Message) Select Case m.Msg Case 132 'Click & Drag Form...
5
by: sierra7 | last post by:
Hi I have been writing Access applications for some years now and have moved away from from the 'Switchboard' type of opening form to using a menubar accross the top of the screen and borderless...
2
by: plevintampabay | last post by:
I have a borderless form in C#. The form has an icon specified in its properties and I also have the same icon specified for the project in the project properties. When I had a border on the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.