[英]how to get cpu state in C#
我是C#和編程的新手。
我創建了一個簡單的plc程序(步驟7),在PLSIM模擬器上進行了模擬。 我想使用Siemens S7ProSim COM Object
參考,使用C#中的WPF接口控制該程序。
這是問題所在:當我想為標簽分配CPU狀態時,顯示此消息:
錯誤1'System.Windows.Controls.Label'不包含'Text'的定義,並且找不到擴展方法'Text'接受類型為'System.Windows.Controls.Label'的第一個參數(您是否缺少使用指令還是程序集引用?)C:\\ Users \\ Lenovo \\ Documents \\ Visual Studio 2010 \\ Projects \\ CSProject \\ CSProject \\ MainWindow.xaml.cs 32 28 CSProject這是我的程序和wpf接口:
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.