-5
我有这样的代码:如何将表单转换为类?
主营:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace TestApp
{
class Program
{
static void Main()
{
WC W1 = WC.CreateWindow("", "");
}
}
}
WindowControl:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
public class WC
{
public static Form CreateWindow(string name, string title)
{
Form nform = new Form();
nform.Name = name;
nform.Text = title;
Application.EnableVisualStyles();
Application.Run(nform);
return nform;
}
public static void DeleteWindow(Form name)
{
name.Close();
}
}
但我得到这个错误:
Cannot implicitly convert type 'System.Windows.Forms.Form' to 'WC'.
我在做什么错了?
'形式W1 = WC.CreateWindow( “”, “”);'或'VAR W1 = WC.CreateWindow( “” ,“”);'或者只是'WC.CreateWindow(“”,“”);'因为你还没有使用变量。 –
'WC.CreateWindow'返回* Form * not * WC *。所以更改为'表格W1 = WC.CreateWindow(“”,“”);' – Eser