-
Notifications
You must be signed in to change notification settings - Fork 0
/
extUtilities.vb
102 lines (90 loc) · 4.55 KB
/
extUtilities.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Public Class extUtilities
'This class has some random snippets that would be useful in the zippo application
'They need modification to fit custom version of the application
'DO NOT USE AS IS, it will NOT work!
Public Function strCurrencyToDecimal(Value As String) As Decimal
'Converts input string to output decimal
'Based on: http://www.velocityreviews.com/forums/t87759-convert-currency-formatted-string-back-to-decimal.html
If Value.Length = 0 Then
Return 0
Else
Value = Value.Replace(",", "").Replace("$", "€").Replace("£", "€").Replace(".", ",")
Return Decimal.Parse(Value.Replace(" ", ""), System.Globalization.NumberStyles.Any Or System.Globalization.NumberStyles.AllowCurrencySymbol _
Or System.Globalization.NumberStyles.AllowThousands Or System.Globalization.NumberStyles.AllowDecimalPoint)
End If
End Function
Public Function ImageSource(ByVal FullPath As String) As Object
'Based on: http://stackoverflow.com/questions/20586/image-urisource-and-data-binding
Dim image As New BitmapImage()
Try
image.BeginInit()
image.CacheOption = BitmapCacheOption.OnLoad
image.CreateOptions = BitmapCreateOptions.IgnoreImageCache
image.UriSource = New Uri(FullPath, UriKind.Absolute)
image.EndInit()
Catch
Return DependencyProperty.UnsetValue
End Try
Return image
End Function
Public Sub PopulateImages()
Dim intImages As Integer = 0
Dim intControls As Integer = 0
' Enumerate all the descendants of the visual object.
' Based on: http://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.getchild.aspx
While intControls < VisualTreeHelper.GetChildrenCount(Me.Content) - 1 And intImages < _zippo.Images.Count
' Retrieve child visual at specified index value.
Dim childVisual As Visual = CType(VisualTreeHelper.GetChild(Me.Content, intControls), Visual)
' Check if visual is an Image type
If childVisual.GetType().Name = "Image" Then
Dim currentImage As Image = CType(childVisual, Image)
' Place uri to source
currentImage.Source = ImageSource(_zippo.Images(intImages).ToString)
currentImage.Stretch = Stretch.Uniform
intImages += 1
End If
intControls += 1
End While
End Sub
'Hiding windows
Private Sub Window_IsVisibleChanged(sender As System.Object, e As System.Windows.DependencyPropertyChangedEventArgs) Handles MyBase.IsVisibleChanged
If Me.Visibility = Windows.Visibility.Hidden Then
Me.Owner.Activate()
End If
End Sub
Private Sub Window_Closing(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
For Each Window As winBrowser In Me.OwnedWindows.OfType(Of winBrowser)()
Window.ParentCloses = True
Next
End Sub
Dim parentWindow As Window
'file browser for images
Private Sub btnBrowse_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnBrowse.Click
Dim openfile As New OpenFileDialog
openfile.Filter = "Image files (*.gif, *.png, *.jpg)|*.gif*;*.png*;*.jpg"
Dim result As DialogResult = openfile.ShowDialog()
If result = DialogResult.OK Then
_filePath = openfile.FileName
'Dim safeFilePath As String = openfile.SafeFileName
txtFilePath.Text = _filePath
End If
End Sub
Private Sub btnReplace_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnReplace.Click
Dim uriExtension As String = ""
uriExtension = txtFilePath.Text.Split(".")(txtFilePath.Text.Split(".").Count - 1)
If uriExtension = "jpg" Or uriExtension = "gif" Or uriExtension = "png" Then
If _filePath <> txtFilePath.Text Then
_filePath = txtFilePath.Text
End If
RaiseEvent ReplaceMe(_filePath.ToString)
'Insinuating fresh startup window when reloaded next time
txtFilePath.Text = String.Empty
parentWindow.Visibility = Windows.Visibility.Hidden
Else
MessageBox.Show("Not a valid image!")
End If
End Sub
Private Sub UserControl_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
parentWindow = Window.GetWindow(Me)
End Sub
End Class