我试图使一个pc诊断工具,我这样做的命令提示符,我试图这样做的windows窗体的IDE,我正在使用的是Visual Studio 2015对不起,如果问题是明显的或无关的,我是新的C#我环顾四周,但无法找到任何有用的处理这个错误-谢谢Mahmood
以下是有效的命令提示符代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
namespace mahmoodspcdiagnostictool_m.p.d.t_
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("To begin diagnostic type start diagnostic");
string startdiagnostic = Console.ReadLine();
if (startdiagnostic == "start diagnostic")
{
PerformanceCounter perfCpuCount = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes");
Console.WriteLine("Cpu Usage: Avalible RAM:");
while (true)
{
Thread.Sleep(2500);
Console.Write("{0}%", perfCpuCount.NextValue());
Console.WriteLine(" {0} MB", perfMemCount.NextValue());
}
}
}
}
}
下面是无法正常工作的Windows窗体代码:
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;
using System.Diagnostics;
using System.Threading;
namespace MahmoodsPCDiagnosticTool_M.P.D.T__GUI_Edition_
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
PerformanceCounter perfCpuCount = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes");
//When the start button is clicked this code is to be executed
private void button1_Click(object sender, EventArgs e)
{
richTextBox4.AppendText("{0}%\r\n", perfCpuCount.NextValue());
richTextBox5.AppendText("{0} MB\r\n", perfMemCount.NextValue());
}
private void Form1_Enter(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is a pc diagnostic tool it was made by Mahmood Badr.");
}
private void richTextBox2_TextChanged(object sender, EventArgs e)
{
}
private void richTextBox4_TextChanged(object sender, EventArgs e)
{
}
}
}
1条答案
按热度按时间lg40wkob1#
您的示例显示如何使用richTextBox,它没有
AppendText(string, string)
方法,只有AppendText(string)
方法。这是可行的: