Results 1 to 5 of 5

Thread: frends i need to convert this code to c#

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2014
    Posts
    169

    frends i need to convert this code to c#

    good day friends;
    i have use this code with vb.net
    i want to convert this code c#
    this code is used to resize control with all size of the form
    thank you in advance

    Code:
    Module Form_Resize_Change
    
        Dim ProportionsArray() As CtrlProportions
    
        Private Structure CtrlProportions
            Dim HeightProportions As Single
            Dim WidthProportions As Single
            Dim TopProportions As Single
            Dim LeftProportions As Single
        End Structure
    
        Sub WhenCreateForm(ByVal MyForm As Form)
            On Error Resume Next
            Application.DoEvents()
            ReDim ProportionsArray(0 To MyForm.Controls.Count - 1)
            For I As Integer = 0 To MyForm.Controls.Count - 1
                With ProportionsArray(I)
                    .HeightProportions = MyForm.Controls(I).Height / MyForm.Height
                    .WidthProportions = MyForm.Controls(I).Width / MyForm.Width
                    .TopProportions = MyForm.Controls(I).Top / MyForm.Height
                    .LeftProportions = MyForm.Controls(I).Left / MyForm.Width
                End With
            Next
        End Sub
        Public Sub ResizeChange(ByVal MyForm As Form)
            On Error Resume Next
            For I As Integer = 0 To MyForm.Controls.Count - 1
                MyForm.Controls(I).Left = ProportionsArray(I).LeftProportions * MyForm.Width
                MyForm.Controls(I).Top = ProportionsArray(I).TopProportions * MyForm.Height
                MyForm.Controls(I).Width = ProportionsArray(I).WidthProportions * MyForm.Width
                MyForm.Controls(I).Height = ProportionsArray(I).HeightProportions * MyForm.Height
            Next
        End Sub
    
    End Module

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: frends i need to convert this code to c#

    That is clearly bad code to begin with, with On Error Resume Next seemingly used without thought. The C# equivalent of that code is going to be almost identical, except that On Error Resume Next has no equivalent. You should replace that with proper exception handling if you think you need it but everything else will barely change. The C# equivalent of a VB module is a static class and a Sub is just a void function. Other than that, if you've taken the time to read the code then should be able to write the C# equivalent to it.

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: frends i need to convert this code to c#

    except that On Error Resume Next has no equivalent
    I had the link below bookmarked some time ago. One of my teammate used it to bypass errors generated by the CMS.
    When the CMS project crashed during testing phase, we had it removed and apply proper error handling mechanism.
    And thus, boomerang! . This is in fact a bad practice. :-D


    On Error Resume Next in C#


    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: frends i need to convert this code to c#

    Quote Originally Posted by KGComputers View Post
    I had the link below bookmarked some time ago. One of my teammate used it to bypass errors generated by the CMS.
    When the CMS project crashed during testing phase, we had it removed and apply proper error handling mechanism.
    And thus, boomerang! . This is in fact a bad practice. :-D


    On Error Resume Next in C#


    - kgc
    In order for the use of try...catch statements to simulate On Error Resume Next you would have to put every single line inside its own exception handler. If you put two lines inside the same try block then an exception on the first would cause the second to be bypassed so it's not doing the same thing.

  5. #5
    Addicted Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    172

    Re: frends i need to convert this code to c#

    except that On Error Resume Next has no equivalent
    In this case PO used it to prevent division to zero exception. Its not always bad to use Resume next when you know what are you doing. And I'm agreed to PO can put what is inside loop inside Try block to prevent division to zero exception when he converting his code.
    Computer Enterprise Masoud Keshavarz
    For more information contact masoudk1990@yahoo.com

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