| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- Python
- Google Spreadsheet
- google apps script
- PostgreSQL
- dataframe
- gas
- Kotlin
- Java
- hive
- PySpark
- SQL
- string
- Github
- Google Excel
- matplotlib
- Apache
- django
- array
- c#
- 파이썬
- PANDAS
- GIT
- numpy
- Tkinter
- Excel
- Presto
- math
- list
- Redshift
- Today
- Total
달나라 노트
C# : MessageBox 본문
MessageBox는 흔히 프로그램을 사용할 때 발생하는 정보창/경고창 입니다.
아래 코드를 봅시다.
using System;
using System.Windows.Forms;
class MyProgram
{
public static void Main()
{
Form fm = new Form();
fm.Width = 500;
fm.Height = 300;
Button btn = new Button();
btn.Parent = fm;
btn.Text = "Button";
void btn_Click(object sender, EventArgs e)
{
MessageBox.Show("Msg Box Content", "Msg Box Title");
}
btn.Click += new EventHandler(btn_Click);
Application.Run(fm);
}
}
위 코드를 실행하면 아래와 같은 Window가 뜹니다.

버튼을 클릭하면 아래와같은 MessageBox가 뜹니다.

void btn_Click(object sender, EventArgs e)
{
MessageBox.Show("Msg Box Content", "Msg Box Title");
}
btn.Click += new EventHandler(btn_Click);
Message Box는 위처럼 MessageBox.Show method를 이용해서 띄울 수 있습니다.
위 예시에서는 Button이 Click되면 MessageBox가 발생하도록 Event를 등록했습니다.
MesaageBox.Show()에서
첫 번쨰 인자는 MessageBox Window 내용에 나타낼 텍스트를 의미합니다.
두 번째 인자는 MessageBox Window 제목에 나타낼 텍스트를 의미합니다.
MessageBox.Show method의 인자는 더 많습니다.
MessageBox.Show(arg1, arg2, arg3, arg4)
arg1 -> MessageBox Window 내용에 나타낼 텍스트를 의미합니다.
arg2 -> MessageBox Window 제목에 나타낼 텍스트를 의미합니다.
arg3 -> MessageBox 버튼 타입을 지정합니다.
arg4 -> MessageBox Icon을 지정합니다.
using System;
using System.Windows.Forms;
class MyProgram
{
public static void Main()
{
Form fm = new Form();
fm.Width = 500;
fm.Height = 300;
Button btn = new Button();
btn.Parent = fm;
btn.Text = "Button";
void btn_Click(object sender, EventArgs e)
{
MessageBox.Show(
"Msg Box Content", "Msg Box Title",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Error
);
}
btn.Click += new EventHandler(btn_Click);
Application.Run(fm);
}
}
MessageBox.Show() method에서 세 번째, 네 번째 인자를 지정해보았습니다.

그러면 MessageBox가 위처럼 바뀝니다.
MessageBoxButtons는 System.Windows.Forms 하위에 있는 MessageBoxButtons 열거체입니다.
다음은 MessageBoxButtons 열거체의 종류입니다.
| MessageBoxButton | Description |
| OK | 확인 버튼만 존재 |
| OKCancel | 확인, 취소 버튼 |
| YesNo | 예, 아니오 버튼 |
| YesNoCancel | 예, 아니오, 취소 버튼 |
MessageBoxIcon은 System.Windows.Forms 하위에 있는 MessageBoxIcon 열거체입니다.
다음은 MessageBoxIcon 열거체의 종류입니다.
| MessageBoxIcon | Description |
| Error | 오류 (X 표시) |
| Information | 정보 아이콘 (둥근 느낌표 모양) |
| Warning | 경고 아이콘 (세모 느낌표 모양) |
| Question | 확인 아이콘 (물음표 모양) |
'C# > C#' 카테고리의 다른 글
| C# : Paint, Graphics, DrawImage, RotateFlip, Invalidate (DrawImage로 이미지 띄우기, Image 회전, Image 확대/축소, 이미지 회전, 이미지 확대/축소, Form 새로고침) (0) | 2022.04.05 |
|---|---|
| C# : PictureBox (사진 띄우기, 도형 그리기, PictureBox의 Invalidate) (0) | 2022.04.05 |
| C# : ShowDialog, Show (새로운 Window 띄우기) (0) | 2022.04.04 |
| C# : MenuStrip, ToolStripMenuItem (0) | 2022.04.04 |
| C# : TextBox (0) | 2022.04.04 |