2014-02-25 23 views
1

我使用Visual Studio 2013專業版,C#, 我已經得到了這些使用和在我的代碼行。C# - 無法使用SystemParameters,「類型或命名空間不存在」

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’(是否缺少程序集引用?)

我真的不明白髮生了什麼,我應該添加更多的東西來使用systemparamaters?

+0

你可以得到表格的高度和寬度,查看我的答案。 – Dayan

回答

3

System.Windows.SystemParameters類在PresentationFramework.dll組件限定,這是WPF UI框架的一部分。

從你的問題來看,你不清楚哪個UI框架是你的目標,但我認爲這是winforms,因爲你的代碼中存在using System.Windows.Forms

刪除,使用和add the relevant assembly references到項目

+0

http://puu.sh/7ankg.png這是它看起來如何,仍然不起作用。 – daktari

+0

目標框架:.NET Framework 4.5 – daktari

+0

@ user3332706老兄,你正在做一個WPF應用程序或winforms應用程序?如果WPF,然後刪除對System.Windows.Forms的引用並添加對「PresentationCore.dll」,「PresentationFramework.dll」,「WindowsBase.dll」和「System.Xaml.dll」的引用,否則您正在查看錯誤的類。 –

0

你需要的引用添加到PresentationFramework.dll

+0

http://puu.sh/7ankg.png這是它的外觀,仍然不起作用。 – daktari

+0

@ user3332706 PresentationFramework缺少那裏,你需要添加它 – JaredPar

0

更新

爲了得到一個表格的屏幕寬度和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 ProjectWinForms ...

0

添加引用PresentationFramework到您的項目,以及using System.Windows;命名空間添加到需要使用SystemParameters的任何文件。

enter image description here

相關問題