Я помогаю преобразовать проект Visual Basic в С#. Ниже приведен исходный код VB в документе Application.Designer.cs:
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.34014
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make changes,
' or if you encounter build errors in this file, go to the Project Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = False
Me.EnableVisualStyles = True
Me.SaveMySettingsOnExit = True
Me.ShutdownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.ePlanSysOman.frmMain
End Sub
End Class
End Namespace
Ниже приведен код, который был результатом преобразования онлайн VB в С#:
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.ApplicationServices;//I added this in
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;//I added this in
namespace My
{
//NOTE: This file is auto-generated; do not modify it directly. To make changes,
// or if you encounter build errors in this file, go to the Project Designer
// (go to Project Properties or double-click the My Project node in
// Solution Explorer), and make changes on the Application tab.
//
internal partial class MyApplication
{
[System.Diagnostics.DebuggerStepThroughAttribute()]
public MyApplication() : base(global::Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
{
this.IsSingleInstance = false;
this.EnableVisualStyles = true;
this.SaveMySettingsOnExit = true;
this.ShutdownStyle = global::Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses;
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
protected virtual void OnCreateMainForm()//I changed "override" to "virtual"
{
this.MainForm = global::ePlanSysOman.frmMain;
}
}
}
Свойства, которые не найдены, следующие:
this.IsSingleInstance
this.EnableVisualStyles
this.SaveMySettingsOnExit
this.ShutdownStyle
this.MainForm
Я посмотрел каждый, и у меня есть правильные пространства имен и сборки для них. Еще две проблемы, с которыми я сталкиваюсь:
base(global::Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
//I receive the following error: "object' does not contain a constructor that takes 1 arguments
а также
global::ePlanSysOman.frmMain
//I receive the following error: 'ePlanSysOman.frmMain' is a 'type', which is not valid in the given context
Код VB не содержит ошибок. Только код С# содержит ошибки. Я не слишком хорошо знаком с любыми языками, и любые советы, которые помогут решить эти ошибки, будут очень оценены.
Для приложений VB существует "Рамка приложений", которая включена по умолчанию и доступна из Project → Properties → Application:
Все, что от вас не входит в список "Не найдено", является частью этого FrameWork, кроме MainForm. Вместо добавления program.cs
в проект, как в С# для отображения формы, VB создает экземпляр основной формы и отображает его из кода разработчика.