From faf55218a3df329e69c901f7d152c054570ed188 Mon Sep 17 00:00:00 2001 From: Emmanuele Sassi Date: Mon, 28 Dec 2015 16:58:25 +0000 Subject: [PATCH] EgtWPFLib 1.6l5 : - primo rilascio. --- EgtCalculator.xaml | 94 ++++ EgtCalculator.xaml.vb | 182 +++++++ EgtKeyboard.xaml | 137 +++++ EgtKeyboard.xaml.vb | 647 ++++++++++++++++++++++++ EgtTextBox.xaml | 8 + EgtTextBox.xaml.vb | 198 ++++++++ EgtWPFLib.sln | 22 + EgtWPFLib.vbproj | 153 ++++++ EgtWPFLibDictionary.xaml | 24 + My Project/AssemblyInfo.vb | 59 +++ My Project/Resources.Designer.vb | 63 +++ My Project/Resources.resx | 117 +++++ My Project/Settings.Designer.vb | 71 +++ My Project/Settings.settings | 7 + Resources/EgtCalculator/DeleteArrow.png | Bin 0 -> 624 bytes Resources/EgtCalculator/V.png | Bin 0 -> 652 bytes Resources/EgtCalculator/X.png | Bin 0 -> 548 bytes Utility.vb | 22 + 18 files changed, 1804 insertions(+) create mode 100644 EgtCalculator.xaml create mode 100644 EgtCalculator.xaml.vb create mode 100644 EgtKeyboard.xaml create mode 100644 EgtKeyboard.xaml.vb create mode 100644 EgtTextBox.xaml create mode 100644 EgtTextBox.xaml.vb create mode 100644 EgtWPFLib.sln create mode 100644 EgtWPFLib.vbproj create mode 100644 EgtWPFLibDictionary.xaml create mode 100644 My Project/AssemblyInfo.vb create mode 100644 My Project/Resources.Designer.vb create mode 100644 My Project/Resources.resx create mode 100644 My Project/Settings.Designer.vb create mode 100644 My Project/Settings.settings create mode 100644 Resources/EgtCalculator/DeleteArrow.png create mode 100644 Resources/EgtCalculator/V.png create mode 100644 Resources/EgtCalculator/X.png create mode 100644 Utility.vb diff --git a/EgtCalculator.xaml b/EgtCalculator.xaml new file mode 100644 index 0000000..75950aa --- /dev/null +++ b/EgtCalculator.xaml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EgtCalculator.xaml.vb b/EgtCalculator.xaml.vb new file mode 100644 index 0000000..2ec00b7 --- /dev/null +++ b/EgtCalculator.xaml.vb @@ -0,0 +1,182 @@ +'---------------------------------------------------------------------------- +' EgalTech 2014-2015 +'---------------------------------------------------------------------------- +' File : EgtCalculator.xaml.vb Data : 28.12.15 Versione : 1 +' Contenuto : Calcolatrice touch per EgtWPFLib. +' +' Creato da : Emmanuele Sassi +' Modificato da : +' +' Modifiche : +' +'---------------------------------------------------------------------------- + +Imports System.Globalization +Imports EgtUILib + +Public Class EgtCalculator + + Private Const ASPECTRATIO = 1 + Private Const WIDTHFONTRATIO = 22 / 426.5 + Private Const BUTTONIMAGERATIO = 65 / 85.3 + + ' Variabile statica che indica se è già aperta una tastiera + Private Shared bIsActive As Boolean = False + + ' Riferimento alla TxBx che ha attivato la tastiera + Private m_SourceTxBx As Primitives.TextBoxBase + + ' Stringa che contiene il messaggio d'errore della calcolatrice + Private m_sErrorString As String = String.Empty + + ' Flag che indica se c'è stato un errore + Private m_bErrorState As Boolean = False + + ' Variabile che conserva l'espressione prima di valutarla per poterla riscrivere nel caso generi un errore + Private m_sBeforeEvaluate As String = String.Empty + + ' Variabile che contiene il risultato numerico + Public m_DoubleResult As Double + ' Evento che indica la chiusura della tastiera + Public Event EgtClosed As EventHandler + + 'Funzione che restituisce il valore di bIsActive per usarlo all'esterno della libreria + Public Shared Function GetbIsActive() + Return bIsActive + End Function + +#Region "Constructors and support functions" + + Sub New(TextBoxBase As Primitives.TextBoxBase, Owner As Window) + InitializeComponent() + 'Me.Owner = Owner + bIsActive = True + m_SourceTxBx = TextBoxBase + Me.Width = Owner.ActualWidth / 4 + Me.Height = Me.Width * (1 / ASPECTRATIO) + Dim FontSize As Double = Width * WIDTHFONTRATIO + Me.Resources("EgtKeyboard_FontSize") = New FontSizeConverter().ConvertFrom(CStr(FontSize)) + 'Me.Top = Owner.Top + (Owner.Height / 2 - Me.Height / 2) + 'Me.Left = Owner.Left + (Owner.Width / 2 - Me.Width / 2) + End Sub + + Sub New(TextBoxBase As Primitives.TextBoxBase, Owner As Window, Width As Double) + InitializeComponent() + 'Me.Owner = Owner + bIsActive = True + m_SourceTxBx = TextBoxBase + Me.Width = Width + Me.Height = Width * (1 / ASPECTRATIO) + Dim FontSize As Double = Width * WIDTHFONTRATIO + Me.Resources("EgtCalculator_FontSize") = New FontSizeConverter().ConvertFrom(CStr(FontSize)) + Dim IconWidth As Double = Width / 5 * BUTTONIMAGERATIO + Me.Resources("EgtCalculator_IconWidth") = New FontSizeConverter().ConvertFrom(CStr(IconWidth)) + 'Me.Top = Owner.Top + (Owner.Height / 2 - Height / 2) + 'Me.Left = Owner.Left + (Owner.Width / 2 - Width / 2) + End Sub + +#End Region + + Private Sub NumericKeyboardWD_Initialized(sender As Object, e As EventArgs) + m_sErrorString = EgtMsg(10200 + 1) + End Sub + + + Private Sub AddCharacter(KeyCharacter As String) + ValueTxBx.Focus() + Dim EventArgs = New TextCompositionEventArgs(Keyboard.PrimaryDevice, New TextComposition(InputManager.Current, Keyboard.FocusedElement, KeyCharacter)) + EventArgs.RoutedEvent = TextInputEvent + InputManager.Current.ProcessInput(EventArgs) + End Sub + + Private Sub NumberBtn_Click(sender As Object, e As RoutedEventArgs) Handles OneBtn.Click, TwoBtn.Click, ThreeBtn.Click, FourBtn.Click, FiveBtn.Click, SixBtn.Click, SevenBtn.Click, EightBtn.Click, NineBtn.Click, ZeroBtn.Click, + PlusBtn.Click, MinusBtn.Click, DotBtn.Click, TimesBtn.Click, DividedBtn.Click + If m_bErrorState Then + m_bErrorState = False + ValueTxBx.Foreground = Brushes.Black + ValueTxBx.TextAlignment = TextAlignment.Right + ValueTxBx.Text = m_sErrorString + End If + Dim KeyButton As Button = e.Source + Dim Key As String = String.Empty + If ReturnKeyNumber(KeyButton, Key) Then + AddCharacter(Key) + End If + End Sub + + Private Function ReturnKeyNumber(KeyButton As Button, ByRef Key As String) + Select Case KeyButton.Name + Case OneBtn.Name + Key = "1" + Return True + Case TwoBtn.Name + Key = "2" + Return True + Case ThreeBtn.Name + Key = "3" + Return True + Case FourBtn.Name + Key = "4" + Return True + Case FiveBtn.Name + Key = "5" + Return True + Case SixBtn.Name + Key = "6" + Return True + Case SevenBtn.Name + Key = "7" + Return True + Case EightBtn.Name + Key = "8" + Return True + Case NineBtn.Name + Key = "9" + Return True + Case ZeroBtn.Name + Key = "0" + Return True + Case PlusBtn.Name + Key = "+" + Return True + Case MinusBtn.Name + Key = "-" + Return True + Case DotBtn.Name + Key = "." + Return True + Case TimesBtn.Name + Key = "*" + Return True + Case DividedBtn.Name + Key = "/" + Return True + End Select + Return False + End Function + + Private Sub BackspaceBtn_Click(sender As Object, e As RoutedEventArgs) Handles BackspaceBtn.Click + ValueTxBx.Focus() + Dim eventArgs As New KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Back) + + eventArgs.RoutedEvent = Keyboard.KeyDownEvent + + InputManager.Current.ProcessInput(eventArgs) + + End Sub + + Private Sub Evaluate() + m_sBeforeEvaluate = ValueTxBx.Text + Dim bOk As Boolean = EgtUILib.EgtLuaEvalNumExpr(ValueTxBx.Text, m_DoubleResult) + If bOk Then + ValueTxBx.Text = m_DoubleResult.ToString(CultureInfo.InvariantCulture) + m_sBeforeEvaluate = String.Empty + Else + m_bErrorState = True + ValueTxBx.Foreground = Brushes.Red + ValueTxBx.TextAlignment = TextAlignment.Left + ValueTxBx.Text = m_sErrorString + End If + End Sub + +End Class diff --git a/EgtKeyboard.xaml b/EgtKeyboard.xaml new file mode 100644 index 0000000..e596405 --- /dev/null +++ b/EgtKeyboard.xaml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + +