Some dialog boxes and the backstage area contain a _____ button, labeled with a question mark (?).

1. MessageBox

    : 창에 텍스트, 버튼 및 아이콘를 사용하여 사용자에게 필요한 정보나 경고 등을 제공

  (1) Fucntion

       1) public static DialogResult Show(string text);

           : 메시지박스의 Text만 입력할때 사용

       2) public static DialogResult Show(string text, string caption);

           : 메시지박스의 Text와 Caption(창의 Name속성)을 입력할때 사용

       3) public static DialogResult Show(string text, string caption, MessageBoxButtons buttons);

           : 메시지박스의 Text와 Caption(창의 Name속성)을 입력하고 메시지 박스의 버튼의 종류를 선택

           : MessageBoxButtons의 경우 enum 으로 되어있으며 

             OK, OKCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel 으로 되어있다.

           i) MessageBoxButtons 의 선언

                // Summary:

    //     Specifies constants defining which buttons to display on a System.Windows.Forms.MessageBox.

    public enum MessageBoxButtons

    {

        // Summary:

        //     The message box contains an OK button.

        OK = 0,

        //

        // Summary:

        //     The message box contains OK and Cancel buttons.

        OKCancel = 1,

        //

        // Summary:

        //     The message box contains Abort, Retry, and Ignore buttons.

        AbortRetryIgnore = 2,

        //

        // Summary:

        //     The message box contains Yes, No, and Cancel buttons.

        YesNoCancel = 3,

        //

        // Summary:

        //     The message box contains Yes and No buttons.

        YesNo = 4,

        //

        // Summary:

        //     The message box contains Retry and Cancel buttons.

        RetryCancel = 5,

    }

    4) public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);

           : 메시지박스의 Text와 Caption(창의 Name속성)을 입력하고 메시지 박스의 버튼의 종류를 선택하고 어떤 아이콘을 사용할지 선택

           : MessageBoxButtons의 경우 enum 으로 되어있으며 

             OK, OKCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel 으로 되어있다.( '3)' 참고)

           : MessageBoxIcon의 경우 enum 으로 되어있으며 

        // Summary:

        //     Specifies constants defining which information to display.

        public enum MessageBoxIcon

        {

            // Summary:

            //     The message box contain no symbols.

None = 0,

//

// Summary:

//     The message box contains a symbol consisting of white X in a circle with

//     a red background.

Error = 16,

//

// Summary:

//     The message box contains a symbol consisting of a white X in a circle with

 //     a red background.

Hand = 16,

//

 // Summary:

 //     The message box contains a symbol consisting of white X in a circle with

 //     a red background.

Stop = 16,

//

 // Summary:

 //     The message box contains a symbol consisting of a question mark in a circle.

 //     The question-mark message icon is no longer recommended because it does not

 //     clearly represent a specific type of message and because the phrasing of

 //     a message as a question could apply to any message type. In addition, users

 //     can confuse the message symbol question mark with Help information. Therefore,

 //     do not use this question mark message symbol in your message boxes. The system

 //     continues to support its inclusion only for backward compatibility.

Question = 32,

//

 // Summary:

 //     The message box contains a symbol consisting of an exclamation point in a

 //     triangle with a yellow background.

Exclamation = 48,

//

 // Summary:

 //     The message box contains a symbol consisting of an exclamation point in a

 //     triangle with a yellow background.

Warning = 48,

//

 // Summary:

 //     The message box contains a symbol consisting of a lowercase letter i in a

 //     circle.

Information = 64,

//

 // Summary:

 //     The message box contains a symbol consisting of a lowercase letter i in a

 //     circle.

Asterisk = 64,

}

2. DialogResult  

    : 창(메시지 박스를 비롯한 모든 Form)이 닫힐때 결과값을 남기는 것으로 닫혔을때

      어떠한 이유로 창을 닫았는지 Return 해주는 값이다.

    : enum 형식으로 None, Cancle, Abort, Retry, Ignore, Yes, No 등의 값을 담는다.

   (1) DialogResult  정의된 내용

    // Summary:

    //     Specifies identifiers to indicate the return value of a dialog box.

    [ComVisible(true)]

    public enum DialogResult

    {

        // Summary:

        //     Nothing is returned from the dialog box. This means that the modal dialog

        //     continues running.

        None = 0,

        //

        // Summary:

        //     The dialog box return value is OK (usually sent from a button labeled OK).

        OK = 1,

        //

        // Summary:

        //     The dialog box return value is Cancel (usually sent from a button labeled

        //     Cancel).

        Cancel = 2,

        //

        // Summary:

        //     The dialog box return value is Abort (usually sent from a button labeled

        //     Abort).

        Abort = 3,

        //

        // Summary:

        //     The dialog box return value is Retry (usually sent from a button labeled

        //     Retry).

        Retry = 4,

        //

        // Summary:

        //     The dialog box return value is Ignore (usually sent from a button labeled

        //     Ignore).

        Ignore = 5,

        //

        // Summary:

        //     The dialog box return value is Yes (usually sent from a button labeled Yes).

        Yes = 6,

        //

        // Summary:

        //     The dialog box return value is No (usually sent from a button labeled No).

        No = 7,

    }

Ex) MessageBox 와 DialogResult 를 사용하여 폼의 버튼 클릭시 이벤트 발생

        // MessageBox의 return 값을 result(var type)에 담는다.. 

        DialogResult result = MessageBox.Show("You Click Button!!!", "Button Click"

                                                                  , MessageBoxButtons.OK, MessageBoxIcon.Information);

        // result 값을 확인하고 다른 처리를 할수 있다

        if (result == System.Windows.Forms.DialogResult.OK)

        {

            MessageBox.Show("You Click \"OK\"");

        }

※ 참조 : //msdn.microsoft.com/ko-kr/library/system.windows.forms.messagebox(v=vs.100).aspx

Toplist

Neuester Beitrag

Stichworte