[Converter] VB zu C#, Code funktioniert nicht so wie in VB

  • C#
  • .NET (FX) 3.0–3.5

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von ThuCommix.

    [Converter] VB zu C#, Code funktioniert nicht so wie in VB

    Hallo liebes Forum,

    um ein bestimmtes Control abzurunden, benutze ich in Visual Basic.NET folgenden Code:

    Visual Basic-Quellcode

    1. Private Sub Round(ByVal ObjForm As Object, ByVal iX As Integer, ByVal iY As Integer, ByVal iWidth As Integer, ByVal iHeight As Integer, ByVal iRadius As Integer)
    2. Dim gp As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath()
    3. gp.AddLine(iX + iRadius, iY, iX + Width - iRadius, iY)
    4. gp.AddArc(iX + Width - iRadius, iY, iRadius, iRadius, 270, 90)
    5. gp.AddLine(iX + Width, iY + iRadius, iX + iWidth, iY + iHeight - iRadius)
    6. gp.AddArc(iX + Width - iRadius, iY + Height - iRadius, iRadius, iRadius, 0, 90)
    7. gp.AddLine(iX + iWidth - iRadius, iY + iHeight, iX + iRadius, iY + iHeight)
    8. gp.AddArc(iX, iY + iHeight - iRadius, iRadius, iRadius, 90, 90)
    9. gp.AddLine(iX, iY + Height - iRadius, iX, iY + iRadius)
    10. gp.AddArc(iX, iY, iRadius, iRadius, 180, 90)
    11. gp.CloseFigure()
    12. ObjForm.region = New System.Drawing.Region(gp)
    13. gp.Dispose()
    14. End Sub


    Mit dem Converter von DeveloperFusion bekomme ich folgenden Code in C#/CSharp:

    C#-Quellcode

    1. private void Round(object ObjForm, int iX, int iY, int iWidth, int iHeight, int iRadius)
    2. {
    3. System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
    4. gp.AddLine(iX + iRadius, iY, iX + Width - iRadius, iY);
    5. gp.AddArc(iX + Width - iRadius, iY, iRadius, iRadius, 270, 90);
    6. gp.AddLine(iX + Width, iY + iRadius, iX + iWidth, iY + iHeight - iRadius);
    7. gp.AddArc(iX + Width - iRadius, iY + Height - iRadius, iRadius, iRadius, 0, 90);
    8. gp.AddLine(iX + iWidth - iRadius, iY + iHeight, iX + iRadius, iY + iHeight);
    9. gp.AddArc(iX, iY + iHeight - iRadius, iRadius, iRadius, 90, 90);
    10. gp.AddLine(iX, iY + Height - iRadius, iX, iY + iRadius);
    11. gp.AddArc(iX, iY, iRadius, iRadius, 180, 90);
    12. gp.CloseFigure();
    13. ObjForm.region = new System.Drawing.Region(gp);
    14. gp.Dispose();
    15. }


    Nur ich bekomme bei ObjForm.region = new System.Drawing.Region(gp);, folgenden Fehler:

    Microsoft Visual C# Express 2010 schrieb:


    Fehler 2 "object" enthält keine Definition für "region", und es konnte keine Erweiterungsmethode "region" gefunden werden, die ein erstes Argument vom Typ "object" akzeptiert. (Fehlt eine Using-Direktive oder ein Assemblyverweis?)


    Die Verweise:

    C#-Quellcode

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Text;
    7. using System.Windows.Forms;
    8. using System.Drawing;
    9. using KitchenC.Properties;
    10. using System.Drawing.Drawing2D;


    Kann mir kurz jemand erklären wie ich dies abändern kann bzw. was falsch ist? Habt Ihr einen Link oder einen Denkanstoß?

    Gruß,
    Jan
    Software being "Done" is like lawn being "Mowed". (Jim Benson)
    Der VB-Code ist noch von einem sehr alten Projekt, ich stelle es mal auf Strict On um und gucke was er sagt^^

    Er sagt nun Option Strict On lässt spätes binden nicht zu, wie kann ich diesen Fehler beheben?
    Software being "Done" is like lawn being "Mowed". (Jim Benson)
    Du willst hier die Region eines Form-Objekts einstellen, also übergibst du der Methode auch ein Form-Objekt.

    Visual Basic-Quellcode

    1. Private Sub Round(ByVal ObjForm As Form, ....

    bzw.

    C#-Quellcode

    1. private void Round(Form ObjForm, ...