Imports System.Windows.Forms
Public Class FrmError
    Inherits System.Windows.Forms.Form

    Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Integer, ByVal lpszExeFileName As String, ByVal nIconIndex As Integer) As Integer
    Private Declare Function DrawIcon Lib "user32.dll" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal hIcon As Integer) As Integer
    Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Integer) As Integer


    Private mIcon As Integer = 0
    Private mReturnValue As DialogResult = DialogResult.OK
    Private mExpand As Boolean = False

#Region " Code généré par le Concepteur Windows Form "
    Public Sub New()
        MyBase.New()

        'Cet appel est requis par le Concepteur Windows Form.
        InitializeComponent()

        'Ajoutez une initialisation quelconque après l'appel InitializeComponent()

    End Sub
    'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Requis par le Concepteur Windows Form
    Private components As System.ComponentModel.IContainer

    'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
    'Elle peut être modifiée en utilisant le Concepteur Windows Form.  
    'Ne la modifiez pas en utilisant l'éditeur de code.
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents CmdShowDetail As System.Windows.Forms.Button
    Friend WithEvents ImgDetail As System.Windows.Forms.ImageList
    Friend WithEvents CmdCopy As System.Windows.Forms.Button
    Friend WithEvents PictIcon As System.Windows.Forms.PictureBox
    Friend WithEvents LblMessage As System.Windows.Forms.Label
    Friend WithEvents CmdOK As System.Windows.Forms.Button
    Friend WithEvents CmdCancel As System.Windows.Forms.Button
    Friend WithEvents CmdYes As System.Windows.Forms.Button
    Friend WithEvents CmdNo As System.Windows.Forms.Button
    Friend WithEvents CmdRetry As System.Windows.Forms.Button
    Friend WithEvents CmdIgnore As System.Windows.Forms.Button
    Friend WithEvents CmdAbort As System.Windows.Forms.Button
    Friend WithEvents TxtDetail As System.Windows.Forms.TextBox
    Friend WithEvents PanBtn As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FrmError))
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.LblMessage = New System.Windows.Forms.Label
        Me.PictIcon = New System.Windows.Forms.PictureBox
        Me.PanBtn = New System.Windows.Forms.Panel
        Me.CmdAbort = New System.Windows.Forms.Button
        Me.CmdIgnore = New System.Windows.Forms.Button
        Me.CmdRetry = New System.Windows.Forms.Button
        Me.CmdNo = New System.Windows.Forms.Button
        Me.CmdYes = New System.Windows.Forms.Button
        Me.CmdCancel = New System.Windows.Forms.Button
        Me.CmdOK = New System.Windows.Forms.Button
        Me.CmdCopy = New System.Windows.Forms.Button
        Me.CmdShowDetail = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.TxtDetail = New System.Windows.Forms.TextBox
        Me.ImgDetail = New System.Windows.Forms.ImageList(Me.components)
        Me.Panel1.SuspendLayout()
        Me.PanBtn.SuspendLayout()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.LblMessage)
        Me.Panel1.Controls.Add(Me.PictIcon)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Panel1.Location = New System.Drawing.Point(0, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(466, 96)
        Me.Panel1.TabIndex = 0
        '
        'LblMessage
        '
        Me.LblMessage.Dock = System.Windows.Forms.DockStyle.Fill
        Me.LblMessage.Location = New System.Drawing.Point(64, 0)
        Me.LblMessage.Name = "LblMessage"
        Me.LblMessage.Size = New System.Drawing.Size(402, 96)
        Me.LblMessage.TabIndex = 1
        Me.LblMessage.Text = "Label1"
        '
        'PictIcon
        '
        Me.PictIcon.Dock = System.Windows.Forms.DockStyle.Left
        Me.PictIcon.Location = New System.Drawing.Point(0, 0)
        Me.PictIcon.Name = "PictIcon"
        Me.PictIcon.Size = New System.Drawing.Size(64, 96)
        Me.PictIcon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictIcon.TabIndex = 0
        Me.PictIcon.TabStop = False
        '
        'PanBtn
        '
        Me.PanBtn.Controls.Add(Me.CmdAbort)
        Me.PanBtn.Controls.Add(Me.CmdIgnore)
        Me.PanBtn.Controls.Add(Me.CmdRetry)
        Me.PanBtn.Controls.Add(Me.CmdNo)
        Me.PanBtn.Controls.Add(Me.CmdYes)
        Me.PanBtn.Controls.Add(Me.CmdCancel)
        Me.PanBtn.Controls.Add(Me.CmdOK)
        Me.PanBtn.Controls.Add(Me.CmdCopy)
        Me.PanBtn.Controls.Add(Me.CmdShowDetail)
        Me.PanBtn.Dock = System.Windows.Forms.DockStyle.Top
        Me.PanBtn.Location = New System.Drawing.Point(0, 96)
        Me.PanBtn.Name = "PanBtn"
        Me.PanBtn.Size = New System.Drawing.Size(466, 40)
        Me.PanBtn.TabIndex = 1
        '
        'CmdAbort
        '
        Me.CmdAbort.DialogResult = System.Windows.Forms.DialogResult.Abort
        Me.CmdAbort.Location = New System.Drawing.Point(360, 0)
        Me.CmdAbort.Name = "CmdAbort"
        Me.CmdAbort.Size = New System.Drawing.Size(80, 23)
        Me.CmdAbort.TabIndex = 8
        Me.CmdAbort.Text = "&Abandonner"
        '
        'CmdIgnore
        '
        Me.CmdIgnore.DialogResult = System.Windows.Forms.DialogResult.Ignore
        Me.CmdIgnore.Location = New System.Drawing.Point(288, 16)
        Me.CmdIgnore.Name = "CmdIgnore"
        Me.CmdIgnore.Size = New System.Drawing.Size(72, 23)
        Me.CmdIgnore.TabIndex = 7
        Me.CmdIgnore.Text = "&Ignorer"
        '
        'CmdRetry
        '
        Me.CmdRetry.DialogResult = System.Windows.Forms.DialogResult.Retry
        Me.CmdRetry.Location = New System.Drawing.Point(288, 0)
        Me.CmdRetry.Name = "CmdRetry"
        Me.CmdRetry.Size = New System.Drawing.Size(72, 23)
        Me.CmdRetry.TabIndex = 6
        Me.CmdRetry.Text = "&Rééssayer"
        '
        'CmdNo
        '
        Me.CmdNo.DialogResult = System.Windows.Forms.DialogResult.No
        Me.CmdNo.Location = New System.Drawing.Point(216, 16)
        Me.CmdNo.Name = "CmdNo"
        Me.CmdNo.Size = New System.Drawing.Size(72, 23)
        Me.CmdNo.TabIndex = 5
        Me.CmdNo.Text = "&Non"
        '
        'CmdYes
        '
        Me.CmdYes.DialogResult = System.Windows.Forms.DialogResult.Yes
        Me.CmdYes.Location = New System.Drawing.Point(216, 0)
        Me.CmdYes.Name = "CmdYes"
        Me.CmdYes.Size = New System.Drawing.Size(72, 23)
        Me.CmdYes.TabIndex = 4
        Me.CmdYes.Text = "&Oui"
        '
        'CmdCancel
        '
        Me.CmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.CmdCancel.Location = New System.Drawing.Point(144, 16)
        Me.CmdCancel.Name = "CmdCancel"
        Me.CmdCancel.Size = New System.Drawing.Size(72, 23)
        Me.CmdCancel.TabIndex = 3
        Me.CmdCancel.Text = "&Annuler"
        '
        'CmdOK
        '
        Me.CmdOK.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.CmdOK.Location = New System.Drawing.Point(144, 0)
        Me.CmdOK.Name = "CmdOK"
        Me.CmdOK.Size = New System.Drawing.Size(72, 23)
        Me.CmdOK.TabIndex = 2
        Me.CmdOK.Text = "&OK"
        '
        'CmdCopy
        '
        Me.CmdCopy.Image = CType(resources.GetObject("CmdCopy.Image"), System.Drawing.Image)
        Me.CmdCopy.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.CmdCopy.Location = New System.Drawing.Point(72, 8)
        Me.CmdCopy.Name = "CmdCopy"
        Me.CmdCopy.Size = New System.Drawing.Size(64, 23)
        Me.CmdCopy.TabIndex = 1
        Me.CmdCopy.Text = "&Copier"
        Me.CmdCopy.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.CmdCopy.Visible = False
        '
        'CmdShowDetail
        '
        Me.CmdShowDetail.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.CmdShowDetail.Location = New System.Drawing.Point(8, 8)
        Me.CmdShowDetail.Name = "CmdShowDetail"
        Me.CmdShowDetail.Size = New System.Drawing.Size(56, 24)
        Me.CmdShowDetail.TabIndex = 0
        Me.CmdShowDetail.Text = "&Détail"
        Me.CmdShowDetail.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.TxtDetail)
        Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupBox1.Location = New System.Drawing.Point(0, 136)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(466, 111)
        Me.GroupBox1.TabIndex = 2
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Détail"
        '
        'TxtDetail
        '
        Me.TxtDetail.Dock = System.Windows.Forms.DockStyle.Fill
        Me.TxtDetail.Location = New System.Drawing.Point(3, 16)
        Me.TxtDetail.Multiline = True
        Me.TxtDetail.Name = "TxtDetail"
        Me.TxtDetail.ReadOnly = True
        Me.TxtDetail.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.TxtDetail.Size = New System.Drawing.Size(460, 92)
        Me.TxtDetail.TabIndex = 0
        Me.TxtDetail.Text = ""
        '
        'ImgDetail
        '
        Me.ImgDetail.ImageSize = New System.Drawing.Size(16, 16)
        Me.ImgDetail.ImageStream = CType(resources.GetObject("ImgDetail.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImgDetail.TransparentColor = System.Drawing.Color.Transparent
        '
        'FrmError
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(466, 247)
        Me.ControlBox = False
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.PanBtn)
        Me.Controls.Add(Me.Panel1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MaximumSize = New System.Drawing.Size(472, 264)
        Me.MinimizeBox = False
        Me.MinimumSize = New System.Drawing.Size(472, 130)
        Me.Name = "FrmError"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "FrmError"
        Me.Panel1.ResumeLayout(False)
        Me.PanBtn.ResumeLayout(False)
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Shadows Function ShowDialog(ByVal pMessage As String, ByVal pDetail As String, ByVal pTitle As String, ByVal pIcon As MessageBoxIcon, ByVal pButtons As MessageBoxButtons, Optional ByVal pDefault As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1) As DialogResult
        Try
            Me.LblMessage.Text = pMessage
            Me.TxtDetail.Text = pDetail
            'Buttons
            Me.CmdAbort.Visible = False
            Me.CmdCancel.Visible = False
            Me.CmdIgnore.Visible = False
            Me.CmdNo.Visible = False
            Me.CmdOK.Visible = False
            Me.CmdRetry.Visible = False
            Me.CmdYes.Visible = False
            Me.CmdAbort.Top = 8
            Me.CmdCancel.Top = Me.CmdAbort.Top
            Me.CmdIgnore.Top = Me.CmdAbort.Top
            Me.CmdNo.Top = Me.CmdAbort.Top
            Me.CmdOK.Top = Me.CmdAbort.Top
            Me.CmdRetry.Top = Me.CmdAbort.Top
            Me.CmdYes.Top = Me.CmdAbort.Top

            Select Case pButtons
                Case MessageBoxButtons.AbortRetryIgnore
                    Me.CmdAbort.Visible = True
                    Me.CmdIgnore.Visible = True
                    Me.CmdRetry.Visible = True
                    CmdIgnore.Left = PanBtn.Width - CmdIgnore.Width - 8
                    CmdRetry.Left = CmdIgnore.Left - CmdRetry.Width - 8
                    CmdAbort.Left = CmdRetry.Left - CmdAbort.Width - 8
                    Select Case pDefault
                        Case MessageBoxDefaultButton.Button1
                            Me.AcceptButton = CmdAbort
                        Case MessageBoxDefaultButton.Button2
                            Me.AcceptButton = CmdRetry
                        Case MessageBoxDefaultButton.Button3
                            Me.AcceptButton = CmdIgnore
                    End Select
                    Me.CancelButton = CmdShowDetail
                Case MessageBoxButtons.OK
                    Me.CmdOK.Visible = True
                    CmdOK.Left = PanBtn.Width - CmdOK.Width - 8
                    Me.AcceptButton = CmdOK
                    Me.CancelButton = CmdShowDetail
                Case MessageBoxButtons.OKCancel
                    Me.CmdCancel.Visible = True
                    Me.CmdOK.Visible = True
                    CmdCancel.Left = PanBtn.Width - CmdCancel.Width - 8
                    CmdOK.Left = CmdCancel.Left - CmdOK.Width - 8
                    Select Case pDefault
                        Case MessageBoxDefaultButton.Button2
                            Me.AcceptButton = CmdCancel
                            Me.CancelButton = CmdOK
                        Case Else
                            Me.AcceptButton = CmdOK
                            Me.CancelButton = CmdCancel
                    End Select
                Case MessageBoxButtons.RetryCancel
                    Me.CmdCancel.Visible = True
                    Me.CmdRetry.Visible = True
                    CmdCancel.Left = PanBtn.Width - CmdCancel.Width - 8
                    CmdRetry.Left = CmdCancel.Left - CmdRetry.Width - 8
                    Select Case pDefault
                        Case MessageBoxDefaultButton.Button2
                            Me.AcceptButton = CmdCancel
                            Me.CancelButton = CmdRetry
                        Case Else
                            Me.AcceptButton = CmdRetry
                            Me.CancelButton = CmdCancel
                    End Select
                Case MessageBoxButtons.YesNo
                    Me.CmdNo.Visible = True
                    Me.CmdYes.Visible = True
                    CmdNo.Left = PanBtn.Width - CmdNo.Width - 8
                    CmdYes.Left = CmdNo.Left - CmdYes.Width - 8
                    Select Case pDefault
                        Case MessageBoxDefaultButton.Button2
                            Me.AcceptButton = CmdNo
                            Me.CancelButton = CmdYes
                        Case Else
                            Me.AcceptButton = CmdYes
                            Me.CancelButton = CmdNo
                    End Select
                Case MessageBoxButtons.YesNoCancel
                    Me.CmdCancel.Visible = True
                    Me.CmdNo.Visible = True
                    Me.CmdYes.Visible = True
                    CmdCancel.Left = PanBtn.Width - CmdCancel.Width - 8
                    CmdNo.Left = CmdCancel.Width - CmdNo.Width - 8
                    CmdYes.Left = CmdNo.Left - CmdYes.Width - 8
                    Select Case pDefault
                        Case MessageBoxDefaultButton.Button1
                            Me.AcceptButton = CmdYes
                        Case MessageBoxDefaultButton.Button2
                            Me.AcceptButton = CmdNo
                        Case MessageBoxDefaultButton.Button3
                            Me.AcceptButton = CmdCancel
                    End Select
                    Me.CancelButton = CmdShowDetail
                Case Else
                    Me.CmdOK.Visible = True
                    CmdOK.Left = PanBtn.Width - CmdOK.Width - 8
                    Me.AcceptButton = CmdOK
                    Me.CancelButton = CmdShowDetail
            End Select

            'Icon
            'USER32.dll
            ' ! 1
            ' ? 2
            ' X 3
            ' I 4
            Select Case pIcon
                Case MessageBoxIcon.Error
                    mIcon = ExtractIcon(Me.Handle.ToInt32, Environment.SystemDirectory + "\user32.dll", 3)
                Case MessageBoxIcon.Exclamation
                    mIcon = ExtractIcon(Me.Handle.ToInt32, Environment.SystemDirectory + "\user32.dll", 1)
                Case MessageBoxIcon.Information
                    mIcon = ExtractIcon(Me.Handle.ToInt32, Environment.SystemDirectory + "\user32.dll", 4)
                Case MessageBoxIcon.Question
                    mIcon = ExtractIcon(Me.Handle.ToInt32, Environment.SystemDirectory + "\user32.dll", 2)
                Case Else
                    mIcon = 0
            End Select

            Return MyBase.ShowDialog()
        Catch ex As System.Exception
            Return DialogResult.None
        End Try
    End Function

    Private Sub FrmError_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CmdShowDetail.Image = ImgDetail.Images(0)
        Me.ClientSize = Me.MinimumSize
    End Sub
    Private Sub FrmError_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If mIcon <> 0 Then
            DestroyIcon(mIcon)
            mIcon = 0
        End If
    End Sub
    Private Sub CmdShowDetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdShowDetail.Click
        If mExpand Then
            Me.ClientSize = Me.MinimumSize
            CmdShowDetail.Image = Me.ImgDetail.Images(0)
            CmdCopy.Visible = False
        Else
            Me.ClientSize = Me.MaximumSize
            CmdShowDetail.Image = Me.ImgDetail.Images(1)
            CmdCopy.Visible = True
        End If
        mExpand = Not (mExpand)
    End Sub
    Private Sub CmdCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCopy.Click
        Clipboard.SetDataObject(TxtDetail.Text, True)
    End Sub

    Private Sub PictIcon_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictIcon.Paint
        If mIcon <> 0 Then
            e.Graphics.DrawIcon(Icon.FromHandle(New IntPtr(mIcon)), Convert.ToInt32((PictIcon.Width - 32) / 2), Convert.ToInt32((PictIcon.Height - 32) / 2))
        End If
    End Sub
End Class
