กล่องข้อความ

การแสดงผลด้วย MessageBox

MessageBox เป็นการแสดงผลในรูปแบบกล่องข้อความ

มีรูปแบบดังนี้


MessageBox.Show("Message", "Title", Button, Icon, DefaultButton);  


โดย  Message           คือ  ข้อความที่ปรากฏในบนหน้าต่าง MessageBox

        Title                  คือ  ข้อความที่ปรากฏบนแถบชื่อเรื่อง (Title Bar)

        Button              คือ  ปุ่มที่ให้ผู้ใช้เลือก หลังอ่านข้อความแล้ว   

        Icon                  คือ  สัญรูปที่เป็นภาพประกอบข้อความ   
DefaultButton คือ  การกำหนดตำแหน่งปุ่มเริ่มต้น
 
ปุ่มที่แสดงผล



การเรียกใช้งาน
ปุ่มที่ปรากฏ
MessageBoxButtons.AbortRetryIgnore
Abort
Retry
Ignore
MessageBoxButton.OK
OK


MessageBoxButton.OKCancel
OK
Cancel

MessageBoxButton.RetryCancel
Retry
Cancel

MessageBoxButton.YesNo
Yes
No

MessageBoxButton.YesNoCancel
Yes
No
Cancel


สัญรูปที่แสดงผล

การเรียกใช้งาน
สัญรูปที่ปรากฏ
MessageBoxIcon.Asterisk MessageBoxIcon.Information
MessageBoxIcon.Error       
MessageBoxIcon.Hand     
MessageBoxIcon.Stop
MessageBoxIcon.Exclamation MessageBoxIcon.Warning
MessageBoxIcon.Question
MessageBoxIcon.None
ไม่แสดงสัญรูป


MessageBox C# การแสดง MessageBox ด้วยภาษา C#
    MessageBox คือ คำ Class ของภาษา C# มีไว้สำหรับการแสดง Message Box หรือหน้าต่างข้อความในรูปแบบต่าง ๆ ซึ่งสามารถใช้งานได้บน Windows Forms Application

    ภาพรวมของ MessageBox 
    1. ใช้คำสั่ง MessageBox.show() ในการแสดงหน้าต่างข้อความ
    2. สามารถส่งค่า Parameter ได้หลายรูปแบบสำหรับการสร้างหน้าตา และเงื่อนไขของ MessageBox

    ตัวอย่างโปรแกรม
    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
    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 WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                MessageBox.Show("Hello, AmplySoft",
                                "Title MessageBox",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Information);
            }
        }
    }

    ผลลัพธ์



ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

เทคโนโลยีเส้นใยผ้าระดับนาโน สร้างพลังงานไฟฟ้า ให้กับอุปกรณ์แบบใหม่ที่ไร้แบตเตอรี่

Upgrade จาก Windows เก่าเป็น Windows 10 ดีอย่างไร