Imports EgtUILib Public Class InternalComponentPageUC 'Riferimento alla MainWindow Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow) Friend CurrentBtn As Button = Nothing Private Sub InternalComponentPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded LoadPage() CurrentBtn = Nothing m_MainWindow.m_DrawPageUC.m_ActiveComponentPage = DrawPageUC.Pages.InternalComponent 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 Friend Function GetIndexFromButton(Button As Button) As Integer Select Case Button.Name Case "Compo1" Return 1 Case "Compo2" Return 2 Case "Compo3" Return 3 Case "Compo4" Return 4 Case "Compo5" Return 5 Case "Compo6" Return 6 Case "Compo7" Return 7 Case Else Return 8 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 CurrentBtn = e.Source Dim CompoName As String = "InternalCompo" & GetIndexFromButton(CurrentBtn).ToString Dim nCompoName As Integer Dim sCompo As String = String.Empty Dim sCompoImage As String = String.Empty GetPrivateProfileCompo(CompoName, CompoName, nCompoName, sCompo, sCompoImage, m_MainWindow.GetIniFile()) m_MainWindow.m_DrawPageUC.DimensionBtn.IsChecked = True m_MainWindow.m_DrawPageUC.SideAngleBtn.IsChecked = False m_MainWindow.m_DrawPageUC.MessageGrid.Visibility = Windows.Visibility.Visible m_MainWindow.m_DrawPageUC.BackBtn.Visibility = Windows.Visibility.Visible m_MainWindow.m_DrawPageUC.PartNumberGrd.Visibility = Windows.Visibility.Visible ' Carico componente m_MainWindow.m_DrawPageUC.SelectedComponent(sCompo) 'Attivo Bottoni aggiungi e rimuovi m_MainWindow.m_DrawPageUC.m_CompoDimension.AddBtn.Visibility = Windows.Visibility.Visible m_MainWindow.m_DrawPageUC.m_CompoDimension.CancelBtn.Visibility = Windows.Visibility.Visible m_MainWindow.m_DrawPageUC.m_CompoDimension.InternComponentBtn.Visibility = Windows.Visibility.Hidden m_MainWindow.m_DrawPageUC.LeftButtonGrd.Children.Remove(Me) m_MainWindow.m_DrawPageUC.VariablesGrd.Children.Add(m_MainWindow.m_DrawPageUC.m_CompoDimension) 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) As Boolean Dim sVal As String = String.Empty GetPrivateProfileString(lpAppName, lpKeyName, "", sVal, lpFileName) Dim sItems() As String = sVal.Split(",".ToCharArray) If sItems.Count() >= 2 Then lpCompoName = 0 StringToInt(sItems(0), lpCompoName) 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 Private Sub ClearButton(nCount As Integer) For index As Integer = 1 To nCount GetLabel(index).Text = String.Empty GetImage(index).Source = Nothing GetButton(index).Visibility = Windows.Visibility.Visible Next For index As Integer = nCount + 1 To 8 GetLabel(index).Text = String.Empty GetImage(index).Source = Nothing GetButton(index).Visibility = Windows.Visibility.Hidden Next End Sub Private Sub LoadPage() ' Leggo numero di componenti presenti Dim nCompoNumber As Integer = GetPrivateProfileInt("InternalCompo", "Count", 0, m_MainWindow.GetIniFile()) ClearButton(nCompoNumber) ' Creazione converter da String a ImageSource Dim ImageConverter As New ImageSourceConverter Dim ThicknessConverter As New ThicknessConverter ' Assegnazione immagine e testo ai Button For index = 1 To 8 Dim CustomThickness As Thickness = ThicknessConverter.ConvertFromString("0") Dim nCompoName As Integer Dim sCompo As String = "" Dim sCompoImage As String = "" m_MainWindow.m_DrawPageUC.m_MainComponentPage.GetPrivateProfileCompo("InternalCompo" & index, "InternalCompo" & index, nCompoName, sCompo, sCompoImage, m_MainWindow.GetIniFile()) Dim sCompoImageSource As ImageSource ' Verifico presenza immagine e la aggiungo If sCompoImage.Length <> 0 Then Try sCompoImageSource = ImageConverter.ConvertFromString(m_MainWindow.GetResourcesDir() & "\" & sCompoImage) GetImage(index).Height = 65 GetImage(index).Width = 65 GetImage(index).Source = sCompoImageSource GetLabel(index).SetValue(Grid.ColumnProperty, 1) GetLabel(index).SetValue(Grid.ColumnSpanProperty, 1) 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 GetLabel(index).SetValue(Grid.ColumnProperty, 0) GetLabel(index).SetValue(Grid.ColumnSpanProperty, 2) End Try Else 'Se non c'è l'immagine azzero la distanza tra testo e immagine CustomThickness.Right = 0 GetImage(index).Margin = CustomThickness GetLabel(index).SetValue(Grid.ColumnProperty, 0) GetLabel(index).SetValue(Grid.ColumnSpanProperty, 2) 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 20 lo taglio If sCompoName.Length > 20 Then sCompoName = sCompoName.Substring(0, 20) 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 30 lo taglio If sCompoName.Length > 30 Then sCompoName = sCompoName.Substring(0, 30) 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 Compo9_Click(sender As Object, e As RoutedEventArgs) Handles Compo9.Click m_MainWindow.m_DrawPageUC.BackBtn_Click(sender, e) End Sub End Class