Results 1 to 9 of 9

Thread: [RESOLVED] Change from VB.NET to C#.NET plaese?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Resolved [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:
    1. //**************************************
    2.     //    
    3.     // Name: Most professional way of moving
    4.     //     a borderless form without APIs and witho
    5.     //     ut mouse pointer coordinates
    6.     // Description:Want to move a form by cl
    7.     //     ick and dragging on the client area beca
    8.     //     use your form is bordless/captionless? T
    9.     //     his IS the way to do it at low level pro
    10.     //     gramming without the use of APIs... full
    11.     //     y .NET-wise.
    12.     // By: Rodolfo Gonzalez Ruiz
    13.     //
    14.     // Assumes:Basically the code uses the W
    15.     //     ndProc and changes the window message to
    16.     //     make it believe that you are clicking on
    17.     //     the form/window title bar.
    18.     //
    19.     // Side Effects:User must click on the f
    20.     //     orm client area, if a control is placed
    21.     //     on top, clicking on it will not drag the
    22.     //     window.
    23.     //
    24.     //This code is copyrighted and has    // limited warranties.Please see http://
    25.     //     [url]www.Planet-Source-Code.com/vb/scripts/Sh[/url]
    26.     //     owCode.asp?txtCodeId=3965&lngWId=10    //for details.    //**************************************
    27.     //    
    28.    
    29.     'Place this code anywhere on your form code
    30.     #Region " ClientAreaMove Handling "
    31.     Const WM_NCHITTEST As Integer = &H84
    32.     Const HTCLIENT As Integer = &H1
    33.     Const HTCAPTION As Integer = &H2
    34.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    35.     Select Case m.Msg
    36.     Case WM_NCHITTEST
    37.     MyBase.WndProc(m)
    38.     If m.Result = HTCLIENT Then m.Result = HTCAPTION
    39.     '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.
    40.     Case Else
    41.     'Make sure you pass unhandled messages back to the default message handler.
    42.     MyBase.WndProc(m)
    43.     End Select
    44.     End Sub
    45.     #End Region
    Thanks

    Tomexx.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Change from VB.NET to C#.NET plaese?

    Heres the result.
    VB Code:
    1. const int WM_NCHITTEST = 132;
    2. const int HTCLIENT = 1;
    3. const int HTCAPTION = 2;
    4.  
    5. protected override void WndProc(ref System.Windows.Forms.Message m)
    6. {
    7.  if (m.Msg == WM_NCHITTEST) {
    8.    base.WndProc(m);
    9.    if (m.Result == HTCLIENT) {
    10.      m.Result = HTCAPTION;
    11.    }
    12.  } else {
    13.    base.WndProc(m);
    14.  }
    15. }
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  6. #6
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    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).
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width