|
-
Jun 28th, 2006, 11:14 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Change from VB.NET to C#.NET plaese?
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, 12:55 PM
#2
Re: Change from VB.NET to C#.NET plaese?
Code:
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.ToInt32() == HTCLIENT) m.Result = new IntPtr(HTCAPTION);
break;
//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.
default:
//Make sure you pass unhandled messages back to the default message handler.
base.WndProc(ref m);
break;
}
}
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 28th, 2006, 12:58 PM
#3
Re: Change from VB.NET to C#.NET plaese?
And for future needs you can use this site to convert from vb > C# and C# > vb.
http://www.developerfusion.co.uk/uti...btocsharp.aspx
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 28th, 2006, 07:41 PM
#4
Re: [RESOLVED] Change from VB.NET to C#.NET plaese?
That converter doesn't do a very good job on the original poster's sample however.
-
Jun 28th, 2006, 09:19 PM
#5
Re: [RESOLVED] Change from VB.NET to C#.NET plaese?
Heres the result.
VB Code:
const int WM_NCHITTEST = 132;
const int HTCLIENT = 1;
const int HTCAPTION = 2;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == WM_NCHITTEST) {
base.WndProc(m);
if (m.Result == HTCLIENT) {
m.Result = HTCAPTION;
}
} else {
base.WndProc(m);
}
}
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 28th, 2006, 10:21 PM
#6
Re: [RESOLVED] Change from VB.NET to C#.NET plaese?
2 adjustments per 10 lines converted is not great (the missing 'ref' on two method calls). Converting a 20,000 line project that way is going to be not much faster than rewriting from scratch. Throw in some generics and you'll really see interesting results from on-line converters.
(ours has 0 adjustments for that sample).
-
Jun 28th, 2006, 10:41 PM
#7
Re: [RESOLVED] Change from VB.NET to C#.NET plaese?
I guess the difference is an understanding of the class library and not just the language. There is nothing in the VB code to suggest that the "ref" is required unless you have some knowledge of the method that's being called. On-line converters are unlikely to have that knowledge. I'd say that $179 is a good price if you did want to convert a major project, but for the most part we are converting snippets.
-
Jun 28th, 2006, 11:31 PM
#8
Re: [RESOLVED] Change from VB.NET to C#.NET plaese?
But the demo is free... (if you're just converting small snippets anyway).
Knowledge of the class library is critical since you're not really converting C# code to VB if you don't know where the 'ref's go. There are many other cases converting in either direction where an aspect is invisible in one language, but visible in another. For example, there is no syntax clue in C# about whether x is a class or an interface in "class foo : x", but it's critical to convert this to "... Inherits x" if it's a class and "... Implements x" if it's an interface when converting C# to VB.
So if a converter leaves off the 'ref', what the converter is really doing is assuming (not even guessing) that all the VB method parameters are 'ByVal'. The on-line converters do a lot of this - there is not even an attempt at heuristics (which we incorporate in converting partial code fragments).
And it's not even just the class library that the on-line converters overlook. If you type in methods with 'ByRef' parameters that are called elsewhere in your sample, you'll see that the 'ref' is still not added. So even the information in the code sample is being overlooked.
-
Jun 28th, 2006, 11:46 PM
#9
Re: [RESOLVED] Change from VB.NET to C#.NET plaese?
Well for a beginner in the .net language the little conversion site is a good help but with learning .net you learn a basic of OOP and the .NET Framework so its all just a matter of learning another languages syntax. I dont see the need to purchase a conversion utility unless you dont want to learn how to program.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
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
|