-
Apr 7th, 2016, 02:37 PM
#1
Thread Starter
Addicted Member
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
-
Apr 7th, 2016, 07:06 PM
#2
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.
-
Apr 7th, 2016, 10:44 PM
#3
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
-
Apr 7th, 2016, 11:07 PM
#4
Re: frends i need to convert this code to c#
Originally Posted by KGComputers
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.
-
Apr 8th, 2016, 03:10 AM
#5
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|