Files
EgtWPFLib/EgtMsgBox.xaml.vb
Renzo Lanza 64ed432c0c EgtWPFLib 2.1i1 :
- Aggiunto EgtWPFLibDarkDictionary.xaml per il cambio tema e adattamento delle altre classi
2019-09-20 12:48:46 +00:00

515 lines
20 KiB
VB.net

Imports EgtUILib
Public Class EgtMsgBox
'Parametri ricevuti
Private m_sTitle As String = String.Empty
Private m_sText As String = String.Empty
Private m_Buttons As Buttons = Buttons.NULL
Private m_Icon As Icons = Icons.NULL
Private m_bProgressBar As Boolean = False
Private m_Width As Double = 0
Private m_WidthType As WidthType = WidthType.NULL
Private m_iExtraColumns As Integer = 0
Private m_iExtraHalfRows As Integer = 0
'Parametri ausiliari
Private m_nRow As Double = 0
Private m_nColumn As Double = 0
'Parametro di ritorno
Public m_nPressedBtn As Integer = -1
' Flag per sapere se dialogo o finestra normale
Private m_bDialog As Boolean = False
' Riferimento alla finestra che contiene la MsgBox
Private m_Owner As Window
' Proprietà che permette di cambiare il Text a finestra già aperta, utile per aggiornare il testo durante i caricamenti
Public Property Text As String
Get
Return m_sText
End Get
Set(value As String)
m_sText = value
TextTxBl.Text = value
End Set
End Property
' Proprietà che permette di cambiare il Value della LoadingPrBr all'esterno della libreria
Public Property LoadingPrBr_Value As Double
Get
Return LoadingPrBr.Value
End Get
Set(value As Double)
LoadingPrBr.Value = value
End Set
End Property
'Enum
Enum Buttons
YES_NO_CANCEL
OK_CANCEL
ONE_TWO
ONE_TWO_THREE
OK
CANCEL
NULL
End Enum
Enum Icons
DANGER
ESCLAMATION
IMAGE
NULL
End Enum
Enum WidthType
GRID
PIXEL
NULL
End Enum
'Costruttori
Sub New(Owner As Window, sTitle As String, sText As String, Buttons As Buttons, Icon As Icons, Optional ExtraColumns As Integer = 0, Optional ExtraHalfRows As Integer = 0)
'Inizializzazione dei membri della classe con i valori ricevuti
m_Owner = Owner
m_sTitle = sTitle
m_sText = sText
m_Buttons = Buttons
m_Icon = Icon
m_WidthType = WidthType.NULL
m_iExtraColumns = ExtraColumns
m_iExtraHalfRows = ExtraHalfRows
' This call is required by the designer.
InitializeComponent()
If InitializeEgtWPFLib.ResourceDictionary = 0 Then
Dim rd As ResourceDictionary = New ResourceDictionary()
rd.Source = New Uri("/EgtWPFLib;component/EgtWPFLibDictionary.xaml", UriKind.Relative)
Me.Resources.Clear()
Me.Resources = rd
Else
Dim rd As ResourceDictionary = New ResourceDictionary()
rd.Source = New Uri("/EgtWPFLib;component/EgtWPFLibDarkDictionary.xaml", UriKind.Relative)
Me.Resources.Clear()
Me.Resources = rd
End If
' Applico i parametri impostati da InitializeEgtWPFLib
If Not IsNothing(InitializeEgtWPFLib.MsgBoxBorder) Then
Me.Background = Brushes.Transparent
Me.Resources("EgtMsgBox_Border") = InitializeEgtWPFLib.MsgBoxBorder
Else
Me.Resources("EgtMsgBox_Border") = Me.Resources("EgtMsgBox_DefaultBorder")
End If
Me.Resources("EgtMsgBox_Button") = InitializeEgtWPFLib.MsgBoxButton
If InitializeEgtWPFLib.MsgBoxTitleFontsize > 0 Then
Me.Resources("EgtMsgBox_TitleFontSize") = New FontSizeConverter().ConvertFrom(CStr(InitializeEgtWPFLib.MsgBoxTitleFontsize))
End If
If InitializeEgtWPFLib.MsgBoxTextFontsize > 0 Then
Me.Resources("EgtMsgBox_TextFontSize") = New FontSizeConverter().ConvertFrom(CStr(InitializeEgtWPFLib.MsgBoxTextFontsize))
End If
' Apro direttamente la finestra
If m_Buttons <> EgtMsgBox.Buttons.NULL Then
m_bDialog = True
Me.ShowDialog()
Else
m_bDialog = False
Me.Show()
End If
End Sub
Sub New(Owner As Window, Width As Double, WidthType As WidthType, sTitle As String, sText As String, Buttons As Buttons, Icon As Icons, Optional ExtraColumns As Integer = 0, Optional ExtraHalfRows As Integer = 0)
'Inizializzazione dei membri della classe con i valori ricevuti
m_Owner = Owner
m_sTitle = sTitle
m_sText = sText
m_Buttons = Buttons
m_Icon = Icon
m_Width = Width
m_WidthType = WidthType
m_iExtraColumns = ExtraColumns
m_iExtraHalfRows = ExtraHalfRows
' This call is required by the designer.
InitializeComponent()
If InitializeEgtWPFLib.ResourceDictionary = 0 Then
Dim rd As ResourceDictionary = New ResourceDictionary()
rd.Source = New Uri("/EgtWPFLib;component/EgtWPFLibDictionary.xaml", UriKind.Relative)
Me.Resources.Clear()
Me.Resources = rd
Else
Dim rd As ResourceDictionary = New ResourceDictionary()
rd.Source = New Uri("/EgtWPFLib;component/EgtWPFLibDarkDictionary.xaml", UriKind.Relative)
Me.Resources.Clear()
Me.Resources = rd
End If
' Applico i parametri impostati da InitializeEgtWPFLib
If Not IsNothing(InitializeEgtWPFLib.MsgBoxBorder) Then
Me.Background = Brushes.Transparent
Me.Resources("EgtMsgBox_Border") = InitializeEgtWPFLib.MsgBoxBorder
Else
Me.Resources("EgtMsgBox_Border") = Me.Resources("EgtMsgBox_DefaultBorder")
End If
Me.Resources("EgtMsgBox_Button") = InitializeEgtWPFLib.MsgBoxButton
If InitializeEgtWPFLib.MsgBoxTitleFontsize > 0 Then
Me.Resources("EgtMsgBox_TitleFontSize") = New FontSizeConverter().ConvertFrom(CStr(InitializeEgtWPFLib.MsgBoxTitleFontsize))
End If
If InitializeEgtWPFLib.MsgBoxTextFontsize > 0 Then
Me.Resources("EgtMsgBox_TextFontSize") = New FontSizeConverter().ConvertFrom(CStr(InitializeEgtWPFLib.MsgBoxTextFontsize))
End If
' Apro direttamente la finestra
If m_Buttons <> EgtMsgBox.Buttons.NULL Then
m_bDialog = True
Me.ShowDialog()
Else
m_bDialog = False
Me.Show()
End If
End Sub
Sub New(Owner As Window, sTitle As String, sText As String, bProgressBar As Boolean, Buttons As Buttons, Icon As Icons, Optional ExtraColumns As Integer = 0, Optional ExtraHalfRows As Integer = 0)
'Inizializzazione dei membri della classe con i valori ricevuti
m_Owner = Owner
m_sTitle = sTitle
m_sText = sText
m_bProgressBar = bProgressBar
m_Buttons = Buttons
m_Icon = Icon
m_WidthType = WidthType.NULL
m_iExtraColumns = ExtraColumns
m_iExtraHalfRows = ExtraHalfRows
' This call is required by the designer.
InitializeComponent()
If InitializeEgtWPFLib.ResourceDictionary = 0 Then
Dim rd As ResourceDictionary = New ResourceDictionary()
rd.Source = New Uri("/EgtWPFLib;component/EgtWPFLibDictionary.xaml", UriKind.Relative)
Me.Resources.Clear()
Me.Resources = rd
Else
Dim rd As ResourceDictionary = New ResourceDictionary()
rd.Source = New Uri("/EgtWPFLib;component/EgtWPFLibDarkDictionary.xaml", UriKind.Relative)
Me.Resources.Clear()
Me.Resources = rd
End If
' Applico i parametri impostati da InitializeEgtWPFLib
If Not IsNothing(InitializeEgtWPFLib.MsgBoxBorder) Then
Me.Background = Brushes.Transparent
Me.Resources("EgtMsgBox_Border") = InitializeEgtWPFLib.MsgBoxBorder
Else
Me.Resources("EgtMsgBox_Border") = Me.Resources("EgtMsgBox_DefaultBorder")
End If
Me.Resources("EgtMsgBox_Button") = InitializeEgtWPFLib.MsgBoxButton
If InitializeEgtWPFLib.MsgBoxTitleFontsize > 0 Then
Me.Resources("EgtMsgBox_TitleFontSize") = New FontSizeConverter().ConvertFrom(CStr(InitializeEgtWPFLib.MsgBoxTitleFontsize))
End If
If InitializeEgtWPFLib.MsgBoxTextFontsize > 0 Then
Me.Resources("EgtMsgBox_TextFontSize") = New FontSizeConverter().ConvertFrom(CStr(InitializeEgtWPFLib.MsgBoxTextFontsize))
End If
' Apro direttamente la finestra
m_bDialog = False
Me.Show()
End Sub
Private Sub EgtMsgBox_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
'Applico il FontFamily alla finestra
Dim EgtFontFamilyConverter As New FontFamilyConverter
Me.FontFamily = EgtFontFamilyConverter.ConvertFromString(InitializeEgtWPFLib.FontFamilyPath)
'Calcolo il numero di righe necessarie
If m_sTitle <> String.Empty Then
m_nRow += 0.5
End If
If m_sText <> String.Empty Then
m_nRow += 1
End If
If m_bProgressBar Then
m_nRow += 1
End If
If m_Buttons <> EgtMsgBox.Buttons.NULL Then
m_nRow += 1.5
End If
m_nRow += m_iExtraHalfRows / 2
' Calcolo il numero di colonne necessarie
Select Case m_Buttons
Case Buttons.YES_NO_CANCEL, Buttons.OK, Buttons.ONE_TWO_THREE
m_nColumn = 5
Case Buttons.OK_CANCEL, Buttons.ONE_TWO
m_nColumn = 4.5
Case Buttons.NULL, Buttons.CANCEL
m_nColumn = 3.5
End Select
m_nColumn += m_iExtraColumns
'Creo la griglia
For Index As Integer = 1 To CInt(2 * m_nRow)
EgtMsgBoxGrid.RowDefinitions.Add(New RowDefinition)
Next
For Index As Integer = 1 To CInt(2 * m_nColumn)
EgtMsgBoxGrid.ColumnDefinitions.Add(New ColumnDefinition)
Next
'Attivo/disattivo gli elementi e li posiziono
If m_sTitle <> String.Empty Then
TitleTxBl.SetValue(Grid.RowProperty, 0)
TitleTxBl.SetValue(Grid.ColumnProperty, 1)
TitleTxBl.SetValue(Grid.ColumnSpanProperty, EgtMsgBoxGrid.ColumnDefinitions.Count - 2)
Else
TitleTxBl.Visibility = Windows.Visibility.Hidden
End If
If m_Icon = Icons.NULL Then
IconImg.Visibility = Windows.Visibility.Hidden
End If
If m_sText <> String.Empty Then
If m_sTitle <> String.Empty Then
TextTxBl.SetValue(Grid.RowProperty, 1)
IconImg.SetValue(Grid.RowProperty, 1)
Else
TextTxBl.SetValue(Grid.RowProperty, 0)
TextTxBl.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center)
IconImg.SetValue(Grid.RowProperty, 0)
IconImg.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center)
End If
If m_Icon <> Icons.NULL Then
TextTxBl.SetValue(Grid.ColumnProperty, 3)
TextTxBl.SetValue(Grid.ColumnSpanProperty, EgtMsgBoxGrid.ColumnDefinitions.Count - 4)
IconImg.SetValue(Grid.ColumnProperty, 1)
IconImg.SetValue(Grid.ColumnSpanProperty, 2)
IconImg.SetValue(Grid.RowSpanProperty, 2)
Else
TextTxBl.SetValue(Grid.ColumnProperty, 1)
TextTxBl.SetValue(Grid.ColumnSpanProperty, EgtMsgBoxGrid.ColumnDefinitions.Count - 2)
TextTxBl.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center)
End If
TextTxBl.SetValue(Grid.RowSpanProperty, 2 + m_iExtraHalfRows)
Else
TextTxBl.Visibility = Windows.Visibility.Hidden
IconImg.Visibility = Windows.Visibility.Hidden
End If
If m_bProgressBar Then
If m_sTitle <> String.Empty Then
If m_sText <> String.Empty Then
LoadingPrBr.SetValue(Grid.RowProperty, 3 + m_iExtraHalfRows)
Else
LoadingPrBr.SetValue(Grid.RowProperty, 1)
End If
Else
If m_sText <> String.Empty Then
LoadingPrBr.SetValue(Grid.RowProperty, 2 + m_iExtraHalfRows)
Else
LoadingPrBr.SetValue(Grid.RowProperty, 0)
End If
End If
LoadingPrBr.SetValue(Grid.ColumnProperty, 1)
LoadingPrBr.SetValue(Grid.ColumnSpanProperty, EgtMsgBoxGrid.ColumnDefinitions.Count - 2)
Else
LoadingPrBr.Visibility = Windows.Visibility.Hidden
End If
If m_Buttons <> Buttons.NULL Then
If m_sTitle <> String.Empty Then
If m_sText <> String.Empty Then
If m_bProgressBar Then
Btn1.SetValue(Grid.RowProperty, 5 + m_iExtraHalfRows)
Btn2.SetValue(Grid.RowProperty, 5 + m_iExtraHalfRows)
Btn3.SetValue(Grid.RowProperty, 5 + m_iExtraHalfRows)
Else
Btn1.SetValue(Grid.RowProperty, 3 + m_iExtraHalfRows)
Btn2.SetValue(Grid.RowProperty, 3 + m_iExtraHalfRows)
Btn3.SetValue(Grid.RowProperty, 3 + m_iExtraHalfRows)
End If
Else
If m_bProgressBar Then
Btn1.SetValue(Grid.RowProperty, 3)
Btn2.SetValue(Grid.RowProperty, 3)
Btn3.SetValue(Grid.RowProperty, 3)
Else
Btn1.SetValue(Grid.RowProperty, 1)
Btn2.SetValue(Grid.RowProperty, 1)
Btn3.SetValue(Grid.RowProperty, 1)
End If
End If
Else
If m_sText <> String.Empty Then
If m_bProgressBar Then
Btn1.SetValue(Grid.RowProperty, 4 + m_iExtraHalfRows)
Btn2.SetValue(Grid.RowProperty, 4 + m_iExtraHalfRows)
Btn3.SetValue(Grid.RowProperty, 4 + m_iExtraHalfRows)
Else
Btn1.SetValue(Grid.RowProperty, 2 + m_iExtraHalfRows)
Btn2.SetValue(Grid.RowProperty, 2 + m_iExtraHalfRows)
Btn3.SetValue(Grid.RowProperty, 2 + m_iExtraHalfRows)
End If
Else
If m_bProgressBar Then
Btn1.SetValue(Grid.RowProperty, 2)
Btn2.SetValue(Grid.RowProperty, 2)
Btn3.SetValue(Grid.RowProperty, 2)
Else
Btn1.SetValue(Grid.RowProperty, 0)
Btn2.SetValue(Grid.RowProperty, 0)
Btn3.SetValue(Grid.RowProperty, 0)
End If
End If
End If
Btn1.SetValue(Grid.RowSpanProperty, 2)
Btn2.SetValue(Grid.RowSpanProperty, 2)
Btn3.SetValue(Grid.RowSpanProperty, 2)
End If
Select Case m_Buttons
Case Buttons.YES_NO_CANCEL
Btn1.SetValue(Grid.ColumnProperty, 1 + m_iExtraColumns)
Btn1.SetValue(Grid.ColumnSpanProperty, 2)
Btn1.Content = EgtMsg(MSG_EGTMSGBOX + 3)
Btn2.SetValue(Grid.ColumnProperty, 4 + m_iExtraColumns)
Btn2.SetValue(Grid.ColumnSpanProperty, 2)
Btn2.Content = EgtMsg(MSG_EGTMSGBOX + 4)
Btn3.SetValue(Grid.ColumnProperty, 7 + m_iExtraColumns)
Btn3.SetValue(Grid.ColumnSpanProperty, 2)
Btn3.Content = EgtMsg(MSG_EGTMSGBOX + 2)
Case Buttons.OK_CANCEL
Btn1.SetValue(Grid.ColumnProperty, 2 + m_iExtraColumns)
Btn1.SetValue(Grid.ColumnSpanProperty, 2)
Btn1.Content = EgtMsg(MSG_EGTMSGBOX + 1)
Btn2.Visibility = Windows.Visibility.Hidden
Btn3.SetValue(Grid.ColumnProperty, 5 + m_iExtraColumns)
Btn3.SetValue(Grid.ColumnSpanProperty, 2)
Btn3.Content = EgtMsg(MSG_EGTMSGBOX + 2)
Case Buttons.ONE_TWO
Btn1.SetValue(Grid.ColumnProperty, 2 + m_iExtraColumns)
Btn1.SetValue(Grid.ColumnSpanProperty, 2)
Btn1.Content = "1"
Btn2.Visibility = Windows.Visibility.Hidden
Btn3.SetValue(Grid.ColumnProperty, 5 + m_iExtraColumns)
Btn3.SetValue(Grid.ColumnSpanProperty, 2)
Btn3.Content = "2"
Case Buttons.ONE_TWO_THREE
Btn1.SetValue(Grid.ColumnProperty, 1 + m_iExtraColumns)
Btn1.SetValue(Grid.ColumnSpanProperty, 2)
Btn1.Content = "1"
Btn2.SetValue(Grid.ColumnProperty, 4 + m_iExtraColumns)
Btn2.SetValue(Grid.ColumnSpanProperty, 2)
Btn2.Content = "2"
Btn3.SetValue(Grid.ColumnProperty, 7 + m_iExtraColumns)
Btn3.SetValue(Grid.ColumnSpanProperty, 2)
Btn3.Content = "3"
Case Buttons.OK
Btn1.SetValue(Grid.ColumnProperty, 4 + m_iExtraColumns)
Btn1.SetValue(Grid.ColumnSpanProperty, 2)
Btn1.Content = EgtMsg(MSG_EGTMSGBOX + 1)
Btn2.Visibility = Windows.Visibility.Hidden
Btn3.Visibility = Windows.Visibility.Hidden
Case Buttons.CANCEL
Btn1.Visibility = Windows.Visibility.Hidden
Btn2.Visibility = Windows.Visibility.Hidden
Btn3.SetValue(Grid.ColumnProperty, 2 + m_iExtraColumns)
Btn3.SetValue(Grid.ColumnSpanProperty, 3)
Btn3.SetValue(Grid.RowProperty, 5)
Btn3.SetValue(Grid.RowSpanProperty, 2)
Btn3.Content = EgtMsg(MSG_EGTMSGBOX + 2)
Case Buttons.NULL
Btn1.Visibility = Windows.Visibility.Hidden
Btn2.Visibility = Windows.Visibility.Hidden
Btn3.Visibility = Windows.Visibility.Hidden
End Select
'If m_bProgressBar Then
' Btn1.Visibility = Windows.Visibility.Hidden
' Btn2.Visibility = Windows.Visibility.Hidden
' Btn3.Visibility = Windows.Visibility.Visible
' Btn3.SetValue(Grid.ColumnProperty, 2 + m_iExtraColumns)
' Btn3.SetValue(Grid.ColumnSpanProperty, 3)
' Btn3.SetValue(Grid.RowProperty, 5)
' Btn3.SetValue(Grid.RowSpanProperty, 2)
' Btn3.Content = EgtMsg(MSG_EGTMSGBOX + 2)
'End If
'Assegno agli elementi i valori ricevuti
TitleTxBl.Text = m_sTitle
TextTxBl.Text = m_sText
Dim sImagePath As String = String.Empty
Select Case m_Icon
Case Icons.DANGER
sImagePath = InitializeEgtWPFLib.MsgBoxDangerPath
Case Icons.ESCLAMATION
sImagePath = InitializeEgtWPFLib.MsgBoxExclamationPath
Case Icons.IMAGE
sImagePath = InitializeEgtWPFLib.MsgBoxImagePath
End Select
If m_Icon <> Icons.NULL Then
Try
IconImg.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri(sImagePath, UriKind.Absolute))
Catch ex As Exception
EgtOutLog("Errore nel caricamento dell'icona dell'EgtMsgBox")
End Try
End If
'Calcolo dimensioni e posizione della finestra
Select Case m_WidthType
Case WidthType.NULL
Me.Height = m_Owner.Height / InitializeEgtWPFLib.BaseGridHeight * m_nRow
Me.Width = m_Owner.Width / InitializeEgtWPFLib.BaseGridWidth * m_nColumn
Case WidthType.GRID
Me.Height = m_Owner.Height / InitializeEgtWPFLib.BaseGridHeight * m_nColumn * m_Width / m_nRow
Me.Width = m_Owner.Width / InitializeEgtWPFLib.BaseGridWidth * m_Width
Case WidthType.PIXEL
' Fisso il minimo a 250 pixel perchè più piccola diventa inutilizzabile
If m_Width < 250 Then
m_Width = 250
End If
Me.Height = m_Width / m_nColumn * m_nRow
Me.Width = m_Width
End Select
Me.Top = m_Owner.Top + (m_Owner.Height / 2) - (Me.Height / 2)
Me.Left = m_Owner.Left + (m_Owner.Width / 2) - (Me.Width / 2)
'Assegno la finestra come figlia della MainWindow
Me.Owner = m_Owner
End Sub
Private Sub Btn1_Click(sender As Object, e As RoutedEventArgs) Handles Btn1.Click
m_nPressedBtn = 1
If m_bDialog Then
DialogResult = True
End If
End Sub
Private Sub Btn2_Click(sender As Object, e As RoutedEventArgs) Handles Btn2.Click
m_nPressedBtn = 2
If m_bDialog Then
DialogResult = False
End If
End Sub
Private Sub Btn3_Click(sender As Object, e As RoutedEventArgs) Handles Btn3.Click
m_nPressedBtn = 0
If m_bDialog Then
DialogResult = False
End If
End Sub
End Class