08b4c12d6b
- Migliorata visualizzazione nomi componenti.
203 lines
7.2 KiB
VB.net
203 lines
7.2 KiB
VB.net
Imports EgtUILib
|
|
|
|
Public Class MainComponentPageUC
|
|
|
|
'Riferimento alla MainWindow
|
|
Private m_MainWindow As MainWindow = Application.Current.MainWindow
|
|
|
|
'Dichiarazione delle Page UserControl
|
|
Friend m_SecondaryComponentPage As SecondaryComponentPageUC
|
|
|
|
Friend CurrentBtn As Button = Nothing
|
|
|
|
Private Sub MainComponentPage_Initialized(sender As Object, e As EventArgs)
|
|
|
|
'Creazione delle Page UserControl
|
|
m_SecondaryComponentPage = New SecondaryComponentPageUC
|
|
'Posizionemento nella griglia delle Page UserControl
|
|
m_SecondaryComponentPage.SetValue(Grid.ColumnProperty, 0)
|
|
m_SecondaryComponentPage.SetValue(Grid.RowSpanProperty, 2)
|
|
|
|
' Creazione converter da String a ImageSource
|
|
Dim ImageConverter As New ImageSourceConverter
|
|
Dim ThicknessConverter As New ThicknessConverter
|
|
|
|
'Assegnazione immagine e testo ai Button
|
|
Dim nCompoNumber As Integer = GetPrivateProfileInt("Compo", "Count", 0, m_MainWindow.GetIniFile())
|
|
For index As Integer = 1 To nCompoNumber
|
|
Dim CustomThickness As Thickness = ThicknessConverter.ConvertFromString("0")
|
|
Dim nCompoName As Integer = GetPrivateProfileInt("Compo" & index, "Name", 0, m_MainWindow.GetIniFile())
|
|
Dim sCompoImage As String = ""
|
|
Dim sCompoImageSource As ImageSource
|
|
|
|
'verifico presenza immagine e la aggiungo
|
|
If GetPrivateProfileString("Compo" & index, "Image", "", sCompoImage, m_MainWindow.GetIniFile()) <> 0 Then
|
|
Try
|
|
sCompoImageSource = ImageConverter.ConvertFromString(m_MainWindow.GetResourcesDir() & "\" & sCompoImage)
|
|
GetImage(index).Height = 65
|
|
GetImage(index).Width = 65
|
|
GetImage(index).Source = sCompoImageSource
|
|
Catch ex As Exception
|
|
EgtOutLog("Error loading image " & sCompoImage)
|
|
sCompoImage = String.Empty
|
|
GetImage(index).Height = 0
|
|
GetImage(index).Width = 0
|
|
CustomThickness.Right = 0
|
|
GetImage(index).Margin = CustomThickness
|
|
End Try
|
|
Else
|
|
'Se non c'è l'immagine azzero la distanza tra testo e immagine
|
|
CustomThickness.Right = 0
|
|
GetImage(index).Margin = CustomThickness
|
|
End If
|
|
|
|
'verifico presenza testo
|
|
If nCompoName > 0 Then
|
|
Dim sCompoName As String = EgtMsg(MSG_COMPONENTPAGEUC + nCompoName)
|
|
'verifico presenza immagine
|
|
If sCompoImage.Length > 0 Then
|
|
'se la lunghezza del testo è maggiore di 15 lo taglio
|
|
If sCompoName.Length > 15 Then
|
|
sCompoName = sCompoName.Substring(0, 15)
|
|
End If
|
|
GetLabel(index).Text = sCompoName
|
|
'Se ci sono sia testo che immagine imposto un margine di 10
|
|
CustomThickness.Right = 10
|
|
GetImage(index).Margin = CustomThickness
|
|
Else
|
|
'se l'immagine non c'è e il testo è maggiore di 20 lo taglio
|
|
If sCompoName.Length > 20 Then
|
|
sCompoName = sCompoName.Substring(0, 20)
|
|
End If
|
|
GetLabel(index).Text = sCompoName
|
|
End If
|
|
Else
|
|
'Se non c'è testo azzero la distanza tra testo e immagine
|
|
CustomThickness.Right = 0
|
|
GetImage(index).Margin = CustomThickness
|
|
End If
|
|
|
|
Next
|
|
|
|
End Sub
|
|
|
|
Private Sub UserControl_Loaded(sender As Object, e As RoutedEventArgs)
|
|
CurrentBtn = Nothing
|
|
End Sub
|
|
|
|
Private Function GetButton(ByVal nInd As Integer) As Button
|
|
Select Case nInd
|
|
Case 1
|
|
Return Compo1
|
|
Case 2
|
|
Return Compo2
|
|
Case 3
|
|
Return Compo3
|
|
Case 4
|
|
Return Compo4
|
|
Case 5
|
|
Return Compo5
|
|
Case 6
|
|
Return Compo6
|
|
Case 7
|
|
Return Compo7
|
|
Case 8
|
|
Return Compo8
|
|
Case Else
|
|
Return Compo9
|
|
End Select
|
|
End Function
|
|
|
|
Private Function GetLabel(ByVal nInd As Integer) As TextBlock
|
|
Select Case nInd
|
|
Case 1
|
|
Return LabelCompo1
|
|
Case 2
|
|
Return LabelCompo2
|
|
Case 3
|
|
Return LabelCompo3
|
|
Case 4
|
|
Return LabelCompo4
|
|
Case 5
|
|
Return LabelCompo5
|
|
Case 6
|
|
Return LabelCompo6
|
|
Case 7
|
|
Return LabelCompo7
|
|
Case 8
|
|
Return LabelCompo8
|
|
Case Else
|
|
Return LabelCompo9
|
|
End Select
|
|
End Function
|
|
|
|
Private Function GetImage(ByVal nInd As Integer) As Image
|
|
Select Case nInd
|
|
Case 1
|
|
Return ImageCompo1
|
|
Case 2
|
|
Return ImageCompo2
|
|
Case 3
|
|
Return ImageCompo3
|
|
Case 4
|
|
Return ImageCompo4
|
|
Case 5
|
|
Return ImageCompo5
|
|
Case 6
|
|
Return ImageCompo6
|
|
Case 7
|
|
Return ImageCompo7
|
|
Case 8
|
|
Return ImageCompo8
|
|
Case Else
|
|
Return ImageCompo9
|
|
End Select
|
|
End Function
|
|
|
|
Private Sub Compo_Click(sender As Object, e As RoutedEventArgs) Handles Compo1.Click, Compo2.Click, Compo3.Click, Compo4.Click, Compo5.Click, Compo6.Click, Compo7.Click, Compo8.Click, Compo9.Click
|
|
CurrentBtn = e.Source
|
|
Dim nCount As Integer = GetPrivateProfileInt(CurrentBtn.Name, "Count", 0, m_MainWindow.GetIniFile())
|
|
If nCount > 1 Then
|
|
m_MainWindow.m_DrawPageUC.LeftButtonGrid.Children.Remove(Me)
|
|
m_MainWindow.m_DrawPageUC.m_ActiveComponentPage = DrawPageUC.Pages.SecondaryComponent
|
|
m_MainWindow.m_DrawPageUC.LeftButtonGrid.Children.Add(m_SecondaryComponentPage)
|
|
Else
|
|
Dim nCompoName As Integer
|
|
Dim sCompo As String = String.Empty
|
|
Dim sCompoImage As String = String.Empty
|
|
GetPrivateProfileCompo(CurrentBtn.Name, "Compo1", nCompoName, sCompo, sCompoImage, m_MainWindow.GetIniFile())
|
|
|
|
m_MainWindow.m_DrawPageUC.LeftButtonGrid.Children.Remove(Me)
|
|
m_MainWindow.m_DrawPageUC.VariablesCompoGrid.Visibility = Windows.Visibility.Visible
|
|
' Carico componente
|
|
m_MainWindow.m_DrawPageUC.SelectedComponent(sCompo)
|
|
End If
|
|
End Sub
|
|
|
|
Public Function GetPrivateProfileCompo(
|
|
ByVal lpAppName As String,
|
|
ByVal lpKeyName As String,
|
|
ByRef lpCompoName As Integer,
|
|
ByRef lpCompo As String,
|
|
ByRef lpCompoImage As String,
|
|
ByVal lpFileName As String)
|
|
|
|
Dim sVal As String = String.Empty
|
|
GetPrivateProfileString(lpAppName, lpKeyName, "", sVal, lpFileName)
|
|
Dim sItems() As String = sVal.Split(",".ToCharArray)
|
|
If sItems.Count() >= 2 Then
|
|
lpCompoName = Int(sItems(0))
|
|
lpCompo = sItems(1)
|
|
If sItems.Count() >= 3 Then
|
|
lpCompoImage = sItems(2)
|
|
Else
|
|
lpCompoImage = String.Empty
|
|
End If
|
|
Return True
|
|
End If
|
|
Return False
|
|
|
|
End Function
|
|
|
|
End Class
|