초보의 아웅다웅 설계하기/비주얼 C#

VB.NET CustomMsgBox

로망와니 2013. 7. 8. 22:06

Public Class CustomMsgBox
    Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
    Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean

    Private Const MF_BYPOSITION = &H400
    Private Const MF_REMOVE = &H1000
    Private Const MF_DISABLE = &H2

    Private Sub DisableCloseButton(ByVal hWnd As IntPtr)
        Dim hmenu As IntPtr : Dim menuItemCount As Integer
        hmenu = GetSystemMenu(hWnd, False)
        menuItemCount = GetMenuItemCount(hmenu)

        Call RemoveMenu(hmenu, menuItemCount - 1, MF_DISABLE Or MF_BYPOSITION)
        Call RemoveMenu(hmenu, menuItemCount - 2, MF_DISABLE Or MF_BYPOSITION)
        Call DrawMenuBar(hWnd)

    End Sub

    Enum CustomMsgBoxResult
        Yes
        No
    End Enum

    Enum CustomMsgboxButtons
        OK
        Cancel
        Yes
        No
    End Enum

    Enum CustomMsgboxBgimage
        WarningOK
        WarningYesNo
        InformationOk
        InformationYesNo
    End Enum


    Public Result As CustomMsgBoxResult

    Public Overloads Function Show(ByVal mParent As Form, ByVal mText As String, ByVal mIcon As Integer) As Integer
        Label1.Text = mText
        Me.Icon = mParent.Icon
        If mIcon = 0 Then
            Panel1.BackgroundImage = My.Resources.PNG_WARNING_OK '//130706
            btnMsgBox1.Visible = False
            btnMsgBox2.Visible = True
        ElseIf mIcon = 1 Then
            Panel1.BackgroundImage = My.Resources.PNG_WARNING_YESNO '//130706
            btnMsgBox1.Visible = True
            btnMsgBox2.Visible = True
        ElseIf mIcon = 2 Then
            Panel1.BackgroundImage = My.Resources.PNG_INFOMATION_OK '//130706
            btnMsgBox1.Visible = False
            btnMsgBox2.Visible = True
        Else
            Panel1.BackgroundImage = My.Resources.PNG_INFOMATION_YESNO '//130706
            btnMsgBox1.Visible = True
            btnMsgBox2.Visible = True
        End If

        Me.ShowDialog(mParent)

        Return Result
    End Function

        Private Function hWnd() As IntPtr
        Throw New NotImplementedException
    End Function

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMsgBox2.Click
        Result = CustomMsgBoxResult.No
        Me.Close()
    End Sub

    Private Sub btnMsgBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMsgBox1.Click
        Result = CustomMsgBoxResult.Yes
        Me.Close()
    End Sub
End Class

 

 

 

 

-- 사용 --

            If CustomMsgBox.Show(Me, "Check Step Motor Drv. Com Line.", CustomMsgBox.CustomMsgboxBgimage.WarningYesNo) = CustomMsgBox.CustomMsgBoxResult.No Then
                CustomMsgBox.Show(Me, "No", CustomMsgBox.CustomMsgboxBgimage.InformationOk)
            Else
                CustomMsgBox.Show(Me, "Yes", CustomMsgBox.CustomMsgboxBgimage.InformationYesNo)
            End If

'초보의 아웅다웅 설계하기 > 비주얼 C#' 카테고리의 다른 글

Bluetooth의 시작  (0) 2018.04.22
C# TextBox 속도와 WordWrap = false 처리  (0) 2018.04.01
Visual Studio - error MSB8020  (0) 2017.07.25
C# - 배포판 만들기  (0) 2011.04.06
비주얼 C#  (0) 2010.12.07