Repository navigation
Expand file tree
/
Copy pathForm.vb
More file actions
85 lines (65 loc) · 3.27 KB
/
Copy pathForm.vb
File metadata and controls
85 lines (65 loc) · 3.27 KB
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
Option Strict On
Option Explicit On
Imports Microsoft.Win32
Imports System.Deployment.Application
Imports System.Drawing
Imports System.IO
Imports System.Reflection
Namespace Scripts
Public Class Form
''' <summary>
''' Set form icon
''' </summary>
''' <param name="currentForm">the current form object</param>
''' <param name="bmp">the icon referenced for the form</param>
Public Sub SetIcon(ByRef currentForm As System.Windows.Forms.Form, ByRef bmp As Bitmap)
Try
currentForm.Icon = Icon.FromHandle(bmp.GetHicon)
Catch ex As Exception
ErrorHandler.DisplayMessage(ex)
Finally
Logging.InsertRecordInfo()
End Try
End Sub
''' <summary>
''' set the icon in add/remove programs
''' </summary>
''' <param name="iconName">The referenced icon name for the application.</param>
''' <remarks>
''' only run if deployed
''' </remarks>
Public Sub SetAddRemoveProgramsIcon(iconName As String)
Try
If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed AndAlso ApplicationDeployment.CurrentDeployment.IsFirstRun Then
Dim code As Assembly = Assembly.GetExecutingAssembly()
Dim asdescription As AssemblyDescriptionAttribute = DirectCast(Attribute.GetCustomAttribute(code, GetType(AssemblyDescriptionAttribute)), AssemblyDescriptionAttribute)
Dim assemblyDescription As String = asdescription.Description
'Get the assembly information
Dim assemblyInfo As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
'CodeBase is the location of the ClickOnce deployment files
Dim uriCodeBase As New Uri(assemblyInfo.CodeBase)
Dim clickOnceLocation As String = Path.GetDirectoryName(uriCodeBase.LocalPath.ToString())
'the icon is included in this program
Dim iconSourcePath As String = Path.Combine(clickOnceLocation, Convert.ToString("Resources\") & iconName)
If Not File.Exists(iconSourcePath) Then
Return
End If
Dim myUninstallKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
Dim mySubKeyNames As String() = myUninstallKey.GetSubKeyNames()
For i As Integer = 0 To mySubKeyNames.Length - 1
Dim myKey As RegistryKey = myUninstallKey.OpenSubKey(mySubKeyNames(i), True)
Dim myValue As Object = myKey.GetValue("DisplayName")
If myValue IsNot Nothing AndAlso myValue.ToString() = assemblyDescription Then
myKey.SetValue("DisplayIcon", iconSourcePath)
Exit For
End If
Next
End If
Catch ex As Exception
ErrorHandler.DisplayMessage(ex, True)
Finally
Logging.InsertRecordInfo()
End Try
End Sub
End Class
End Namespace