Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-Can';t使用“系统参数”;类型或命名空间不存在";_C#_Namespaces - Fatal编程技术网

C#-Can';t使用“系统参数”;类型或命名空间不存在";

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

我使用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;
但是,它遇到了一个错误,如“命名空间“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你可以得到表格的高度和宽度,检查我的答案。