C#-Can';t使用“系统参数”;类型或命名空间不存在";
我使用Visual Studio 2013 Professional,C#, 我的代码中有这些用法和那一行C#-Can';t使用“系统参数”;类型或命名空间不存在";,c#,namespaces,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.Ta
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;
但是,它遇到了一个错误,如“命名空间“System.Windows”中不存在类型或命名空间名称“SystemParameters”(是否缺少程序集引用?”
我真的不明白发生了什么,我应该添加更多的东西来使用系统参数吗?您需要添加对PresentationFramework.dll的引用该类是在
PresentationFramework.dll
程序集中定义的,它是WPF UI框架的一部分
您的问题不清楚您针对的是哪个UI框架,但我认为这是winforms,因为您的代码中存在使用System.Windows.Forms的
使用并将其删除到项目中更新
要获取窗体的屏幕宽度和屏幕高度,只需执行以下操作:
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项目
;您和正在尝试使用WPF组件
PresentationFramework(PresentationFramework.dll)实现
最终用户呈现功能,包括布局、时间相关、,
基于故事板的动画和数据绑定
添加项目参考
- 在解决方案资源管理器中,展开项目,右键单击
引用
,然后单击添加引用
- 现在单击底部的“浏览”,找到您尝试使用的DLL。
在这种情况下,它应该包含在
程序集-框架下。单击左侧菜单上的Framework
- 找到右侧的
PresentationFramework
。确保选中它
- 单击“确定”
现在您有了引用,回到您的代码,它应该可以工作了。同样,确保您创建了一个WPF项目
而不是WinForms
…将引用PresentationFramework
添加到您的项目中,并使用System.Windows添加代码>名称空间到任何需要使用SystemParameters
的文件
@user3332706 PresentationFramework缺少,您需要添加it@user3332706伙计,你是在做WPF应用程序还是winforms应用程序?如果是WPF,则删除对System.Windows.Forms的引用,并添加对PresentationCore.dll
、PresentationFramework.dll
、WindowsBase.dll
、和System.Xaml.dll
的引用,否则您将看到错误的类。这是Windows窗体应用程序,我不能获得屏幕宽度或屏幕高度吗?@user3332706是的,您可以获得窗体宽度和高度<代码>变量高度=this.Size.height代码>和var-width=this.Size.width代码>你可以得到表格的高度和宽度,检查我的答案。