Topic : How to Create RAM and CPU Moniter Using C#:

RAM & CPU Monitor:

RAM and CPU Monitor is a small meter which is resides on Our desktop and Provides Useful Information About Our computer's processor and memory Usage. In this tutorial, we will create our Own CPU & RAM Monitor with real time charts using Metro Framework. Follow the Given Steps to Make this Application:



  • Open Visual Studios, create new Project ( Visual C# > Windows forms Application ) write the Project name and click ok.


Download Metro Framework:

Metro Framework is an Open Source DLL. we can give High Level Windows Application design by Using Metro Framework. To download Metro frame work, follow the given steps:


  • » From Solution Explorer Write Click on your Project Name, and select Manage NutGet Packages.
    » Search for Metro Framework
    » Select the latest version as shown in the picture.
    » Click Install.

    Our Metro Framework has been install, now we can move on.



CPU and RAM Meter : infobrother

After Installation, Rebuild the Project (To Rebuild the Project, Open Solution Explorer, right click on the Project, and click on Rebuild. After that, Go to Your Project Form, Double Click on it, and Now you need to change a single line from the code. Our Class Used to Inherit the Properties and Methods from base class Form, But in this example, we will Inherit the properties from Base Class MetroFramework.Forms.MetroForm. We will create form-class like this:


public partial class Form1 : MetroFramework.Forms.MetroForm
{
   public Form1()
    {
       InitializeComponent();
    }
}


After Changing this code, go back to your form, and you'll feel something different. Now drag and Drop controls on form Using tool box as shown in the picture.


CPU and RAM Meter : infobrother
  • In Above Picture, we did Following Steps:

    1 » Drag and Drop PerformanceCounter for RAM. Assign it unique Name as i did and set the properties as shown in Fig-1.
    2 » Drag and Drop another PerformanceCounter for CPU. Assign it unique Name as i did and set the properties as shown in Fig-2.
    3 » Drag and Drop Timer , set the properties as shown in Fig-3. Open the Events Tab and double click on Tick to open the code.
    4 » Go back to form and Drag and Drop two MetroProgressBar, one for CPU and One For RAM. assign different names for both.
    5 » Drag and Drop two MetroLabel, one for CPU and One For RAM. Assign Different Names for Both. and right text 0% as i did.
    6 » Drag and Drop Chart, and from properties, select Series > Collection. and set the ChartType Line. Give it name for CPU. and press the button Add. and one more same member for RAM too.



If You Didn't found Metro Framework Toolkit in your Toolbox, Follow these steps to Get the Toolkit in your Toolbox.


CPU and RAM Meter: infobrother
  • In Above Picture, we did Following Steps:

    1 » Right Click anywhere in the Toolbox. and Select Add Tab. Assign MetroFramework Name to that Tab.
    2 » Right Click on that new added MetroFramework Tab, and Select Choose Items.
    3 » Browse the File > (To Open the file > go to your folder where your save this project and follow this path packages > MetroModernUI > lib > net
    4 » Select the file MetroFramework.dll and Open it.
    5 » Press Ok. and Now you have MetroFramework toolkit in your ToolBox.



Now Go to your code page, and write Given code for method Timer_Tick, that we Open Using Timer Properties.


private void timer_Tick(object sender, EventArgs e)
{
   float fcpu = perfCounterCPU.NextValue();
   float fram = perfCounterRAM.NextValue();

   //set value to cpu and ram.
   metroProgressBarCPU.Value = (int)fcpu;
   metroProgressBarRAM.Value = (int)fram;

  //Update Value to CPU and RAM Label.
  metroLabelCPU.Text = string.Format("{0:0.00}%", fcpu);
  metroLabelRAM.Text = string.Format("{0:0.00}%", fram);

  //Draw cpu and RAM Chart.
  chart1.Series["CPU"].Points.AddY(fcpu);
  chart1.Series["RAM"].Points.AddY(fram);
}


Now double click on anywhere in the form and write the give code to start the timer.


//start the Timer:
private void Form1_Load(object sender, EventArgs e)
{
   timer.Start();
}


CPU and RAM Meter : infobrother
















I Tried my Best to Provide you complete Information regarding this topic in very easy and conceptual way. but still if you have any Problem to understand this topic, or do you have any Questions, Feel Free to Ask Question. i'll do my best to Provide you what you need.

Sardar Omar.
InfoBrother





WRITE FOR INFOBROTHER

Advertising






Advertisement