C# - 无法使用SystemParameters,“类型或命名空间不存在”

时间:2014-02-25 21:03:18

标签: c# namespaces

我使用Visual Studio 2013 Professional,C#, 我的代码中有这些用法和那一行。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;               
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;

然而它有一个类似“类型或命名空间名称'的错误'SystemParameters'在命名空间'System.Windows'中不存在(你是否缺少程序集引用?)

我真的不明白最新情况,我是否应该添加更多内容以使用系统管理员?

4 个答案:

答案 0 :(得分:4)

System.Windows.SystemParameters类在PresentationFramework.dll程序集中定义,它是WPF UI Framework的一部分。

从您的问题中不清楚您正在定位哪个UI框架,但由于您的代码中存在using System.Windows.Forms,我认为它是winforms。

使用和add the relevant assembly references删除项目

答案 1 :(得分:1)

<强>更新

要获取表单的ScreenWidth和ScreenHeight,只需执行以下操作:

var height = this.Size.Height; //Gets the current Height of the Form.
var width  = this.Size.Width; //Gets the current Width of the Form.

this.Size = new Size(1000, 200); // Sets new Width/Height for form.

您需要引用DLL。我还有一种感觉,当你真正想要winforms时,你创建了一个WPF Project项目;您并且正在尝试使用WPF组件...

  

PresentationFramework(presentationframework.dll)实现了   最终用户表现特征,包括布局,时间依赖,   基于故事板的动画和数据绑定。

添加项目参考

  • 在解决方案资源管理器中,展开项目,右键单击References,然后点击Add Reference
  • 现在单击底部的“浏览”,找到您要使用的DLL。 在这种情况下,它应该包含在Assemblies - Framework下。点击左侧菜单中的Framework
  • 在右侧查找PresentationFramework。确保勾选标记
  • 单击“确定”。

现在你有了参考,回到你的代码,它应该工作。同样,请务必创建WPF Project而不是WinForms ...

答案 2 :(得分:0)

您需要添加对PresentationFramework.dll的引用

答案 3 :(得分:0)

将引用PresentationFramework添加到项目中,并将using System.Windows;命名空间添加到需要使用SystemParameters的任何文件中。

enter image description here