在c#项目

时间:2016-12-06 16:55:53

标签: c# reference

我是c#和visual studio的新手,遇到了一些麻烦。

我在visual studio中创建了一个引用“Windows”和“.Net”的项目,因为我想用智能卡测试一下。 代码:

using System;
using Windows.Devices.Enumeration;
using Windows.Devices.SmartCards;

class HandleSmartCard 
{
    public async void checkNumberOfSmartCards()
    {
        string selector = SmartCardReader.GetDeviceSelector();
        DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
        //  return "2";
    }
}

到目前为止看起来很好。但是我也希望项目能够使用 System.Windows.Forms的;我在previos测试中使用过的。 我添加了对System.Windows.Forms的引用;并尝试创建一个表单。但是,当我尝试这种形式时:

Form prompt = new Form();
System.Windows.Forms.Button confirmation = new System.Windows.Forms.Button() { Dock = DockStyle.Bottom };
confirmation.Click += (sender, e) => { prompt.Close(); };

我在“关闭”下面出了一条红线,上面写着:

  

引用类型组件声明它在系统中定义但可以   找不到。

系统在文件顶部被引用,但我猜它是错误的系统类型对吗? 我可以在一个项目中以某种方式使用“两个系统”吗? 我希望有人理解我的意思,并能帮助我理解这一点。

1 个答案:

答案 0 :(得分:1)

您最有可能使用UWP应用。 UWP应用程序的API是完整.NET框架的一小部分。您可以在此处找到更多信息

https://msdn.microsoft.com/en-us/library/windows/apps/mt185501.aspx

您正在尝试引用UWP应用程序中不允许的System.Windows.Forms。

看起来你正在尝试创建一个弹出窗口来询问用户的内容。为此,请使用MessageDialog类。

https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.messagedialog.aspx