C# SystemInformation Class - 시스템 인포메이션 클래스
C# 2021. 12. 3. 17:15 |반응형
시스템 정보를 모두 확인해 보자.
텍스트 박스 속성
Multiline = True
ScrollBars = Vertical
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
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.Reflection;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Type t = typeof(System.Windows.Forms.SystemInformation);
PropertyInfo[] pi = t.GetProperties();
for (int i = 0; i < pi.Length; i++)
listBox1.Items.Add(pi[i].Name);
textBox1.Text = "The SystemInformation class has " + pi.Length.ToString() + " properties.\r\n";
// 한 가지 프로퍼티만 필요하다면 아래와 같이 알아낼 수 있다.
//string propertyName = "CaptionHeight";
//PropertyInfo propertyValue = t.GetProperty(propertyName);
//textBox1.Text = "The value of the " + propertyName + " property is: " + propertyValue.GetValue(null, null).ToString();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// Return if no list item is selected.
if (listBox1.SelectedIndex == -1) return;
// Get the property name from the list item.
string propname = listBox1.Text;
if (propname == "PowerStatus")
{
// Cycle and display the values of each property of the PowerStatus property.
textBox1.Text += "\r\nThe value of the PowerStatus property is:";
Type t = typeof(System.Windows.Forms.PowerStatus);
PropertyInfo[] pi = t.GetProperties();
for (int i = 0; i < pi.Length; i++)
{
object propval = pi[i].GetValue(SystemInformation.PowerStatus, null);
textBox1.Text += "\r\n PowerStatus." + pi[i].Name + " is: " + propval.ToString();
}
}
else
{
// Display the value of the selected property of the SystemInformation type.
Type t = typeof(System.Windows.Forms.SystemInformation);
PropertyInfo[] pi = t.GetProperties();
PropertyInfo prop = null;
for (int i = 0; i < pi.Length; i++)
if (pi[i].Name == propname)
{
prop = pi[i];
break;
}
object propval = prop.GetValue(null, null);
textBox1.Text += "\r\nThe value of the " + propname + " property is: " + propval.ToString();
}
}
}
}
|
소스를 입력하고 빌드한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString(System.Windows.Forms.SystemInformation.BorderSize.ToString(), Font, Brushes.Black, 10, 10);
e.Graphics.DrawString(System.Windows.Forms.SystemInformation.CursorSize.ToString(), Font, Brushes.Black, 10, 30);
e.Graphics.DrawString(System.Windows.Forms.SystemInformation.CaptionHeight.ToString(), Font, Brushes.Black, 10, 50);
}
}
}
|
위와 같이 간단히 몇 개만 조사할 수도 있다.
반응형
'C#' 카테고리의 다른 글
C# Windows Forms Control Library(User Control) - 유저 컨트롤 (0) | 2021.12.04 |
---|---|
C# Control Double Buffering - 컨트롤 더블 버퍼링 (0) | 2021.12.03 |
C# Hide form on Startup - 시작 시 폼 숨기기 (0) | 2021.12.01 |
C# Code Obfuscation - 코드 난독화 (0) | 2021.12.01 |
C# Desktop Capture and Image Display Program - 바탕화면 캡쳐 & 이미지 출력 프로그램 (0) | 2021.11.29 |