112 lines
3.5 KiB
VB.net
112 lines
3.5 KiB
VB.net
Imports System.Drawing
|
|
Imports System.Windows.Forms
|
|
|
|
Public Class frmDialog
|
|
|
|
#Region "WinAPI"
|
|
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
|
|
Public Const HT_CAPTION As Integer = &H2
|
|
<System.Runtime.InteropServices.DllImport("user32.dll")>
|
|
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
|
|
End Function
|
|
<System.Runtime.InteropServices.DllImport("user32.dll")>
|
|
Public Shared Function ReleaseCapture() As Boolean
|
|
End Function
|
|
#End Region
|
|
|
|
Public Enum DialogType
|
|
Warning
|
|
[Error]
|
|
Success
|
|
Info
|
|
Question
|
|
End Enum
|
|
|
|
Public Sub New(pMessageText As String, pTitle As String, pDialogType As DialogType, Optional pCancel As Boolean = False)
|
|
|
|
' Dieser Aufruf ist für den Designer erforderlich.
|
|
InitializeComponent()
|
|
|
|
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
|
txtContent.Text = pMessageText
|
|
txtTitle.Text = pTitle
|
|
|
|
If pCancel Then
|
|
CancelButtonVisible()
|
|
Else
|
|
CancelButtonInvisible()
|
|
End If
|
|
|
|
Select Case pDialogType
|
|
Case DialogType.Success
|
|
pnlContent.BackColor = Color.LightGreen
|
|
SvgImageBox1.SvgImage = SvgImageCollection1.Item("success")
|
|
btnNegative.Visible = False
|
|
SetOkCancelButtons()
|
|
|
|
Case DialogType.Info
|
|
pnlContent.BackColor = Color.LightBlue
|
|
SvgImageBox1.SvgImage = SvgImageCollection1.Item("info")
|
|
btnNegative.Visible = False
|
|
SetOkCancelButtons()
|
|
|
|
Case DialogType.Error
|
|
pnlContent.BackColor = Color.LightCoral
|
|
SvgImageBox1.SvgImage = SvgImageCollection1.Item("error")
|
|
btnNegative.Visible = False
|
|
SetOkCancelButtons()
|
|
|
|
Case DialogType.Warning
|
|
pnlContent.BackColor = Color.LightYellow
|
|
SvgImageBox1.SvgImage = SvgImageCollection1.Item("warning")
|
|
SetOkCancelButtons()
|
|
|
|
Case DialogType.Question
|
|
pnlContent.BackColor = Color.LightYellow
|
|
SvgImageBox1.SvgImage = SvgImageCollection1.Item("question")
|
|
btnNegative.Visible = True
|
|
SetYesNoButtons()
|
|
|
|
|
|
End Select
|
|
|
|
Dim oLineBreaks = txtContent.Text.Split(vbNewLine).Count
|
|
|
|
If oLineBreaks > 6 Then
|
|
Dim oHeightOffset = oLineBreaks * 20
|
|
Height += oHeightOffset
|
|
txtContent.Height += oHeightOffset
|
|
End If
|
|
|
|
btnPositive.Focus()
|
|
End Sub
|
|
|
|
Private Sub SetYesNoButtons()
|
|
btnNegative.Text = "Nein"
|
|
btnNegative.DialogResult = DialogResult.No
|
|
btnPositive.Text = "Ja"
|
|
btnPositive.DialogResult = DialogResult.Yes
|
|
End Sub
|
|
|
|
Private Sub SetOkCancelButtons()
|
|
btnNegative.Text = "Abbrechen"
|
|
btnNegative.DialogResult = DialogResult.Cancel
|
|
btnPositive.Text = "OK"
|
|
btnPositive.DialogResult = DialogResult.OK
|
|
End Sub
|
|
|
|
Public Sub CancelButtonInvisible()
|
|
btnNegative.Visible = False
|
|
End Sub
|
|
Public Sub CancelButtonVisible()
|
|
btnNegative.Visible = True
|
|
End Sub
|
|
|
|
Private Sub Header_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles pnlHeader.MouseDown, txtTitle.MouseDown
|
|
If e.Button = MouseButtons.Left Then
|
|
ReleaseCapture()
|
|
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0)
|
|
End If
|
|
End Sub
|
|
End Class
|