object messagebox


 object messagebox

เมื่อกดปุ่ม Red


กด Yes


กด NO




ถ้ากด Yes จะเปลี่ยนสี

Code "
Public Class Form1
    Const msg = "ต้องการเปลี่ยนสีหรือไหม", title = "ขั้นตอนการเปลี่ยนสี", style = MsgBoxStyle.Question Or MsgBoxStyle.DefaultButton2 Or _
                    MsgBoxStyle.YesNo

    Private Sub btt_Blue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btt_Blue.Click
        Dim response = MsgBox(msg, style, title)
        If response = MsgBoxResult.Yes Then
            MsgBox("โอเค เปลี่ยนเเล้ว", , title)
            Me.BackColor = Color.Blue
        Else
            MsgBox("ครับ ๆ ไม่เปลี่ยนก็ได้", , title)
        End If
    End Sub

สร้างตัวแปลที่มีชื่อว่า msg เก็บค่า "ต้องการเปลี่ยนสีหรือไหม"
สร้างตัวแปลที่มีชื่อว่า title เก็บค่า "ขั้นตอนการเปลี่ยนสี"
สร้างตัวแปลที่มีชื่อว่า style เก็บค่า MsgBoxStyle.Question Or MsgBoxStyle.DefaultButton2 Or _
                    MsgBoxStyle.YesNo

MsgBoxStyle.Question คือ รูป ?
MsgBoxStyle.DefaultButton2 คือ โฟกัสที่ปุ่ม 2 
MsgBoxStyle.YesNo คือ ลักษณะของปุ่มเป็น Yes กับ No

สร้างตัวแปล response เก็บค่า MsgBox(msg, style, title)

โครงสร้าง  object messagebox คือ MsgBox(ข้อความ, ลักษณะ, หัวเรื่อง)

If response = MsgBoxResult.Yes Then 
การนำตัวแปล response  มาเทียบว่าคุณกด Yes หรือไหม ถ้าใช่ให้ทำตามนี้
MsgBox("โอเค เปลี่ยนเเล้ว", , title)
            Me.BackColor = Color.Blue
ถ้าไม่
MsgBox("ครับ ๆ ไม่เปลี่ยนก็ได้", , title)

จบ แม่งงง!

ความคิดเห็น