728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Management;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 타이머
/// </summary>
private Timer timer;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.timer = new Timer();
this.timer.Interval = 1000;
this.startButton.Click += startButton_Click;
this.stopButton.Click += stopButton_Click;
this.timer.Tick += timer_Tick;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 시작 버튼 클릭시 처리하기 - startButton_Click(sender, e)
/// <summary>
/// 시작 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void startButton_Click(object sender, EventArgs e)
{
this.timer.Start();
this.startButton.Enabled = false;
this.stopButton.Enabled = true;
}
#endregion
#region 중단 버튼 클릭시 처리하기 - stopButton_Click(sender, e)
/// <summary>
/// 중단 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void stopButton_Click(object sender, EventArgs e)
{
this.timer.Stop();
this.startButton.Enabled = true;
this.stopButton.Enabled = false;
}
#endregion
#region 타이머 틱 처리하기 - timer_Tick(sender, e)
/// <summary>
/// 타이머 틱 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void timer_Tick(object sender, EventArgs e)
{
int totalMemoryKB = 0;
int totalMemoryMB = 0;
int freeMemoryKB = 0;
int freeMemoryMB = 0;
ManagementClass managementClass = new ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection managementObjectCollection = managementClass.GetInstances();
foreach(ManagementObject managementObject in managementObjectCollection)
{
totalMemoryKB = int.Parse(managementObject["TotalVisibleMemorySize"].ToString());
freeMemoryKB = int.Parse(managementObject["FreePhysicalMemory" ].ToString());
}
totalMemoryMB = totalMemoryKB / 1024;
freeMemoryMB = freeMemoryKB / 1024;
this.totalMemoryProgressBar.Maximum = totalMemoryMB;
this.freeMemoryProgressBar.Maximum = totalMemoryMB;
this.useMemoryProgressBar.Maximum = totalMemoryMB;
this.totalMemoryLabel.Text = $"전체 메모리 : {totalMemoryMB}";
this.freeMemoryLabel.Text = $"여유 메모리 : {freeMemoryMB}";
this.useMemoryLabel.Text = $"사용 메모리 : {totalMemoryMB - freeMemoryMB}";
this.totalMemoryProgressBar.Value = totalMemoryMB;
this.freeMemoryProgressBar.Value = freeMemoryMB;
this.useMemoryProgressBar.Value = (totalMemoryMB - freeMemoryMB);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Label 클래스 : BackColor 속성을 사용해 투명 배경 설정하기 (0) | 2020.05.27 |
---|---|
[C#/WINFORM] Cursor 클래스 : Position 정적 속성을 사용해 크레이지 커서 만들기 (0) | 2020.05.26 |
[C#/WINFORM] 윈도우 메시지(Window Message) 상수 (0) | 2020.05.22 |
[C#/WINFORM] Control 클래스 : ProcessCmdKey 메소드를 사용해 CTRL, SHIFT, ALT 조합 키 입력받기 (0) | 2020.05.22 |
[C#/WINFORM] ImmGetConversionStatus API 함수 : 한/영 키 상태 구하기 (0) | 2020.05.22 |
[C#/WINFORM] SendKeys 클래스 : SendWait 정적 메소드를 사용해 화면 캡처하기 (0) | 2020.05.22 |
[C#/WINFORM] SvgDocument 클래스 : Draw 메소드를 사용해 SVG 이미지 사용하기 (0) | 2020.05.10 |
[C#/WINFORM] Application 클래스 : Restart 정적 메소드를 사용해 애플리케이션 재시작하기 (0) | 2020.03.01 |
[C#/WINFORM] PrinterSettings 클래스 : 디폴트 프린터명 구하기 (0) | 2020.03.01 |
[C#/WINFORM] LoadCursorFromFile API 함수를 사용해 파일에서 커서 로드하기 (0) | 2020.03.01 |
댓글을 달아 주세요