如何在 C# 中获取 cpu 状态
how to get cpu state in C#
我是 C# 和一般编程的新手。
我创建了一个简单的 plc 程序(step7),在 PLSIM 模拟器上模拟。
我想使用 Siemens S7ProSim COM Object
参考在 C# 中使用 WPF 接口控制这个程序。
问题来了:
当我想将 CPU 状态分配给我的标签时,会显示此消息:
Error 1 'System.Windows.Controls.Label' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.Windows.Controls.Label' could be found (are you missing a using directive or an assembly reference?) C:\Users\Lenovo\Documents\Visual Studio 2010\Projects\CSProject\CSProject\MainWindow.xaml.cs 32 28 CSProject
here is my proramm and my wpf interface:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CSProject
{
public partial class MainWindow : Window
{
public S7PROSIMLib.S7ProSim ps = new S7PROSIMLib.S7ProSim();
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ps.Connect();
label_CPUState.Text = ps.GetState();
labelScanMode.Text = ps.GetScanMode().ToString();
}
}
}
非常感谢。
我相信您想要 Label
的 Content
属性,而不是 Text
属性。 Text
是 Winforms。
所以,简单地说:
labelScanMode.Content = ps.GetScanMode().ToString();
我是 C# 和一般编程的新手。
我创建了一个简单的 plc 程序(step7),在 PLSIM 模拟器上模拟。
我想使用 Siemens S7ProSim COM Object
参考在 C# 中使用 WPF 接口控制这个程序。
问题来了: 当我想将 CPU 状态分配给我的标签时,会显示此消息:
Error 1 'System.Windows.Controls.Label' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.Windows.Controls.Label' could be found (are you missing a using directive or an assembly reference?) C:\Users\Lenovo\Documents\Visual Studio 2010\Projects\CSProject\CSProject\MainWindow.xaml.cs 32 28 CSProject here is my proramm and my wpf interface:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CSProject
{
public partial class MainWindow : Window
{
public S7PROSIMLib.S7ProSim ps = new S7PROSIMLib.S7ProSim();
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ps.Connect();
label_CPUState.Text = ps.GetState();
labelScanMode.Text = ps.GetScanMode().ToString();
}
}
}
非常感谢。
我相信您想要 Label
的 Content
属性,而不是 Text
属性。 Text
是 Winforms。
所以,简单地说:
labelScanMode.Content = ps.GetScanMode().ToString();