|
-
Jun 28th, 2006, 11:13 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Convert this from VB.NET to C#.NET
Hi,
Found a "professional way" to drag a borderless form but the sample is written in VB.NET.
Can anyone change it to C# language please?
VB Code:
//**************************************
//
// Name: Most professional way of moving
// a borderless form without APIs and witho
// ut mouse pointer coordinates
// Description:Want to move a form by cl
// ick and dragging on the client area beca
// use your form is bordless/captionless? T
// his IS the way to do it at low level pro
// gramming without the use of APIs... full
// y .NET-wise.
// By: Rodolfo Gonzalez Ruiz
//
// Assumes:Basically the code uses the W
// ndProc and changes the window message to
// make it believe that you are clicking on
// the form/window title bar.
//
// Side Effects:User must click on the f
// orm client area, if a control is placed
// on top, clicking on it will not drag the
// window.
//
//This code is copyrighted and has // limited warranties.Please see http://
// [url]www.Planet-Source-Code.com/vb/scripts/Sh[/url]
// owCode.asp?txtCodeId=3965&lngWId=10 //for details. //**************************************
//
'Place this code anywhere on your form code
#Region " ClientAreaMove Handling "
Const WM_NCHITTEST As Integer = &H84
Const HTCLIENT As Integer = &H1
Const HTCAPTION As Integer = &H2
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_NCHITTEST
MyBase.WndProc(m)
If m.Result = HTCLIENT Then m.Result = HTCAPTION
'If m.Result.ToInt32 = HTCLIENT Then m.Result = IntPtr.op_Explicit(HTCAPTION) 'Try this in VS.NET 2002/2003 if the latter line of code doesn't do it... thx to Suhas for the tip.
Case Else
'Make sure you pass unhandled messages back to the default message handler.
MyBase.WndProc(m)
End Select
End Sub
#End Region
-
Jun 28th, 2006, 01:12 PM
#2
Re: Convert this from VB.NET to C#.NET
Code:
//Place this code anywhere on your form code
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION 0x02;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
base.WndProc(m);
if (m.Result == HTCLIENT)
m.Result = HTCAPTION;
break;
default:
base.WndProc(m);
}
}
C'mon now, I bet you could have done that yourself
Also, there are a lot of VB.NET <-> C# converters (that work with varying degrees of success) floating around for free on the internet. I bet one of them would have nailed this simple snippet right on, while I probably made some subtle, catastrophic mistake that will cause your monitor to explode. Or maybe just get a syntax error somewhere.
HTH!
Last edited by sunburnt; Jun 28th, 2006 at 01:20 PM.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Jun 28th, 2006, 07:16 PM
#3
Re: [RESOLVED] Convert this from VB.NET to C#.NET
Almost ... (but I'm being picky)
Code:
#region ClientAreaMove Handling
private const int WM_NCHITTEST = 0X84;
private const int HTCLIENT = 0X1;
private const int HTCAPTION = 0X2;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (m.Result == HTCLIENT)
m.Result = HTCAPTION;
break;
default:
//Make sure you pass unhandled messages back to the default message handler.
base.WndProc(ref m);
break;
}
}
#endregion
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|