>  기사  >  백엔드 개발  >  C# 메시지박스

C# 메시지박스

WBOY
WBOY원래의
2024-09-03 15:27:42581검색

오늘날의 애플리케이션에서는 사용자가 자신이 수행한 작업의 상태를 알 수 있도록 정보 또는 확인의 토큰으로 메시지가 사용자에게 항상 표시되어야 합니다. 메시지는 "결제가 완료되었습니다" 또는 "계속하시겠습니까?"와 같은 경고 유형 등 무엇이든 될 수 있습니다. 이는 메시지 상자를 사용하여 C#에서 달성됩니다. 메시지 상자는 사용자와 애플리케이션 간의 인터페이스로 간주될 수 있습니다. 사용자에게 무언가를 안내하거나 전달하기 위한 텍스트, 이미지 또는 기호가 있는 창일 뿐입니다. 적절한 작업을 수행하고 메시지 상자를 닫을 때까지 다른 작업을 수행할 수 없습니다.

구문:

Message Box는 “Systems.Windows.Forms” 네임스페이스의 클래스이며 사용 가능한 어셈블리는 “System.Windows.Forms.dll”입니다. 클래스에서 사용 가능한 show 메서드는 메시지와 함께 메시지를 표시하는 데 사용됩니다. 작업 버튼. 작업 버튼은 예부터 아니요, 확인부터 취소까지 다양합니다.

예:

다음 코드는 확인 버튼만으로 간단한 메시지 상자를 생성합니다.

string msg = "Test";
MessageBox.Show(msg);

쇼 방식의 종류

쇼 방식의 종류는 다음과 같습니다.

Syntax Use
MessageBox.Show(String) It will display only the message box with the string that is passed. An ok button is also present to close the dialog.
Example:
Messagebox.Show("Test")
MessageBox.Show( String, String) It will display only the message box with the string that is passed as first parameter. The second parameter is the title of the Message Box. An ok button is also present to close the dialog.
Example:
MessageBox.Show( “Message”, ”Title”).
MessageBox.Show( String,String, MessageBoxButtons) It will display the message box with the supplied text, title and the corresponding buttons to be displayed on the Message Box.
For eg the below will display Yes and No buttons.
MessageBox.Show( "Message”, "Title", MessageBoxButtons.YesNo);
Show(String, String, MessageBoxButtons, MessageBoxIcon) It will display the message box with the supplied text, title and the corresponding buttons to be displayed on the Message Box. It will also display the icon that is specified before the text.
For eg the below will display Yes and No buttons with a question mark in front of message.
MessageBox.Show( "Message”, "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaulButton) It will display the message box with the supplied text, title and the corresponding buttons to be displayed on the Message Box. It will also display the icon that is specified before the text. The last parameter denotes which button must be selected by default on load.
For eg the below will display Yes and No buttons with a question mark in front of message.
MessageBox.Show( "Message”, "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaulButton, MessageBoxOptions) It will display the message box with the supplied text, title, and the corresponding buttons to be displayed on the Message Box. It will also display the icon that is specified before the text. The last parameter denotes which button must be selected by default on load and the contents of the messagebox will be right-aligned.
For eg the below will display Yes and No buttons with a question mark in front of message.
MessageBox.Show( "Message”, "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MesageBoxOptions.RightAlign, true);
구문 사용 MessageBox.Show(문자열) 전달된 문자열이 포함된 메시지 상자만 표시합니다. 대화상자를 닫는 확인 버튼도 있습니다.
예: MessageBox.Show(문자열, 문자열) 첫 번째 매개변수로 전달된 문자열이 포함된 메시지 상자만 표시합니다. 두 번째 매개변수는 메시지 상자의 제목입니다. 대화상자를 닫는 확인 버튼도 있습니다.
예: MessageBox.Show(String,String, MessageBoxButtons) 제공된 텍스트, 제목 및 메시지 상자에 표시되는 해당 버튼이 포함된 메시지 상자를 표시합니다.
예를 들어 아래에는 예 및 아니요 버튼이 표시됩니다. 표시(문자열, 문자열, MessageBoxButtons, MessageBoxIcon) 제공된 텍스트, 제목 및 메시지 상자에 표시될 해당 버튼이 포함된 메시지 상자를 표시합니다. 텍스트 앞에 지정된 아이콘도 표시됩니다.
예를 들어 아래에서는 메시지 앞에 물음표와 함께 예 및 아니요 버튼이 표시됩니다. 표시(문자열, 문자열, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaulButton) 제공된 텍스트, 제목 및 메시지 상자에 표시될 해당 버튼이 포함된 메시지 상자를 표시합니다. 또한 텍스트 앞에 지정된 아이콘도 표시됩니다. 마지막 매개변수는 로드 시 기본적으로 선택해야 하는 버튼을 나타냅니다.
예를 들어 아래에서는 메시지 앞에 물음표와 함께 예 및 아니요 버튼이 표시됩니다. 표시(문자열, 문자열, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaulButton, MessageBoxOptions) 제공된 텍스트, 제목 및 메시지 상자에 표시될 해당 버튼이 포함된 메시지 상자를 표시합니다. 또한 텍스트 앞에 지정된 아이콘도 표시됩니다. 마지막 매개변수는 로드 시 기본적으로 선택되어야 하는 버튼을 나타내며 메시지 상자의 내용은 오른쪽 정렬됩니다.
예를 들어 아래에서는 메시지 앞에 물음표와 함께 예 및 아니요 버튼이 표시됩니다.

Types of MessageBox Buttons

The following are the types of Buttons that are available in the MessageBox.Show() method. They are

  • OK: It is defined as MessageBoxButtons.OK
  • OK and Cancel: It is defined as MessageBoxButtons.OkCancel.
  • Abort Retry and Ignore: It is defined as MessageBoxButtons.AbortRetryIgnore.
  • Yes No and Cancel: It is defined as MessageBoxButtons.YesNoCancel.
  • Yes and No: It is defined as MessageBoxButtons.YesNo.
  • Retry and Cancel: It is defined as MessageBoxButtons.RetryCancel.

Types of MessageBox Icons

The following are the types of MessageBox icons method are:

  • None: No icons are displayed in the Message box.
  • Hand: A hand icon is displayed. It is defined as MessageBoxIcon.Hand.
  • Question: A question mark is displayed. It is defined as MessageBoxIcon.Question.
  • Exclamation: An exclamation mark is displayed. It is defined as MessageBoxIcon.Exclamation.
  • Asterisk: An asterisk symbol is displayed. It is defined as MessageBoxIcon.Asterisk.
  • Stop: A stop icon is displayed. It is defined as MessageBoxIcon.Stop.
  • Error: An error icon is displayed. It is defined as MessageBoxIcon.Error.
  • Warning: A warning icon is displayed. It is defined as MessageBoxIcon.Warning.
  • Information: An info symbol is displayed. It is defined as MessageBoxIcon.Information.

Types of MessageBox Options

The following are the various Message Box options that are available.

  • ServiceNotification: It is defined as MessageBoxOptions.ServiceNotification. This is used to display the message box on the current desktop which is active. The message box is displayed even when no user is logged on to the desktop.
  • DefaultDesktopOnly: It is defined as MessageBoxOptions.DefaultDesktopOnly. This also displays on the currently active desktop. The difference between this and service notification is that here the message is displayed on the interactive window.
  • RightAlign: It is defined as MessageBoxOptions.RightAlign. This is used to format the message in right alignment.
  • RtlReading: It is defined as MessageBoxOptions.RtlReading. This denotes that message is displayed from right to left order.

Example of C# MessageBox

Following are the examples of c# message box are:

Input:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class testform : Form
{
public testform()
{
InitializeComponent();
}
private void testform_Load(object sender, EventArgs e)
{
MessageBox.Show("Demo of MsgBox");
MessageBox.Show("Demo of MsgBox", "Title");
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNo);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.OkCancel);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.RetryCancel);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.OK);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.AbortRetryIgnore);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Hand);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Exclamation);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Asterisk);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Stop);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Error);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Warning);MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Information);MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
MessageBox.Show("Demo of Msgbox","Title",MessageBoxButtons.OK,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
}
}
}

Output:

C# 메시지박스

C# 메시지박스

Conclusion – C# MessageBox

Thus, the article covered in detail about the Message box class in c# in detail. It explained about various message box show methods that are available, the various parameters of each method, and demonstrated that with an example. The article also covered in detail about various message box options, message box buttons, and message box icons in detail along with their use. To learn more in detail it is advisable to write sample programs and practice them.

위 내용은 C# 메시지박스의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:C#의 체크박스다음 기사:C#의 체크박스