如何使用文本框、进度栏和性能计数器中的值进行计算?C#

如何使用文本框、进度栏和性能计数器中的值进行计算?C#,c#,textbox,calculator,performancecounter,divide,C#,Textbox,Calculator,Performancecounter,Divide,我有一个性能计算器,它给了我以KB为单位的内存。 但是我想把这个值除以1000,所以我没有得到更长的KB,而是MB 我试过这个: progressBar9.Value = (int)(performanceCounter9.NextValue()); progressBar9.Value.ToString() / 1000; textBox5.Text = "Max. memory: " + progressBar9.Value.ToString() + " KB";

我有一个性能计算器,它给了我以KB为单位的内存。 但是我想把这个值除以1000,所以我没有得到更长的KB,而是MB

我试过这个:

    progressBar9.Value = (int)(performanceCounter9.NextValue());
    progressBar9.Value.ToString() / 1000;
    textBox5.Text = "Max. memory: " + progressBar9.Value.ToString() + " KB";

我以前从未使用过C#进行计算,因此我对C#

计算有点生疏,这取决于您希望在
progressBar9
(KB或MB)中显示的内容。您可以使用以下内容:

progressBar9.Value=(int)(performanceCounter9.NextValue()/1024)//以MB为单位的值

textBox5.Text=“最大内存:”+progressBar9.Value.ToString()+“MB”

progressBar9.Value=(int)(performanceCounter9.NextValue())//值(KB)

textBox5.Text=“最大内存:”+(progressBar9.Value/1024).ToString()+“MB”

用这个

        pb.Value = (int)(pb.NextValue());
        decimal memory = Convert.ToDecimal(pb.Value) / 1024;
        textBox5.Text = "Max. memory: " + memory.ToString() + " KB";
将其转换为十进制将使您的应用程序能够使用小数而不仅仅是整数


mb中也有1024KB,而不是1000。

目前,您正试图将字符串除以1000,然后对其不做任何操作(中间行)。真的不清楚你想在这里实现什么…我不知道你的意思。我已经说过我是新手了,你能给我一个工作代码的例子吗?谢谢!最后一个是我想要的。然后我该怎么做(progressbar9.value/1024)-prograssbar3.value其他解释:progressbar9/1024,然后是它的答案-progressbar3。value@ThijmenMinecraft,我不知道我是否理解你在这里的意思,你想要类似于:
textBox6.Text=“可用内存:”+((progressBar9.Value/1024)-prograssbar3.Value).ToString()+“MB”
?是的,非常感谢!这正是我的意思!感谢您回答我的问题:-)