【发布时间】:2015-01-16 04:28:53
【问题描述】:
我正在帮助将 Visual Basic 项目转换为 C#。以下是Application.Designer.cs文档中的VB原代码:
'------------------------------------------------------------------------------
' <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 到 C# 转换器的结果代码:
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 代码没有错误。只有 C# 代码包含错误。我对这两种语言都不太熟悉,任何有助于解决这些错误的建议将不胜感激。
【问题讨论】:
-
@Plutonix 那么 C# 会自己处理这些东西,还是如果我删除 Application.Designer.cs 我会被搞砸?
-
VS 自己创建和管理设计器文件 - 你不应该直接编辑它们,除非你真的,真的知道你在做什么。我认为您根本不需要该文件,因为它完全用于实现该 VB App Framework
-
@Plutonix 好的,谢谢你的帮助。
标签: c# vb.net properties namespaces assemblies