C# 无法将类转换为Winform
我正在尝试制作一个Windows窗体应用程序,它可以编译另一个Windows窗体应用程序。但是我在设置运行Winform的默认主方法时,在CodeEntryPointMethod(CodeDom)中设置了几个错误 匹配的最佳重载方法 “System.Windows.Forms.Application.Run(System.Windows.Forms.Form)”已被删除 一些无效的参数 参数“1”无法从转换 “kjpUnityGameLauncherTemplate.Launcher”到“System.Windows.Forms.Form” CodeEntryPointMethod如下所示:C# 无法将类转换为Winform,c#,.net,winforms,class,codedom,C#,.net,Winforms,Class,Codedom,我正在尝试制作一个Windows窗体应用程序,它可以编译另一个Windows窗体应用程序。但是我在设置运行Winform的默认主方法时,在CodeEntryPointMethod(CodeDom)中设置了几个错误 匹配的最佳重载方法 “System.Windows.Forms.Application.Run(System.Windows.Forms.Form)”已被删除 一些无效的参数 参数“1”无法从转换 “kjpUnityGameLauncherTemplate.Launcher”到“Sys
CodeEntryPointMethod start = new CodeEntryPointMethod();
CodeMethodInvokeExpression mainClassSetup = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(typeof(System.Windows.Forms.Application)), "Run",
new CodeObjectCreateExpression(typeof(kjpUnityGameLauncherTemplate.Launcher)));
start.Statements.Add(mainClassSetup);
我的“启动器”类/表格:
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace kjpUnityGameLauncherTemplate
{
public partial class Launcher : Form
{
public Launcher()
{
InitializeComponent();
}
private void Launcher_Load(object sender, EventArgs e)
{
label1.Text = "It works!";
}
}
}
在我看来,你应该把你的类显式地转换成
形式
;但是我该怎么做呢?如果Tico是对的,你应该能够像这样预先编写(表单):(typeof((Form)kjpunitygamelaunchestTemplate.Launcher))
我相信。这不起作用,因为我得到一个错误,说“System.Windows.Forms.Form”是一个类型,但像变量一样使用。