This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LookAndFeelSettingsHelper.vb
83 lines (71 loc) · 2.42 KB
/
LookAndFeelSettingsHelper.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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Imports DevExpress.LookAndFeel
Imports System.Windows.Forms
Namespace WindowsApplication1
<System.ComponentModel.DesignerCategory("")> _
Public Class LookAndFeelSettingsHelper
Inherits Component
Public Sub New()
RestoreSettings()
AddHandler Application.ApplicationExit, AddressOf Application_ApplicationExit
End Sub
' Fields...
Private _FileName As String
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property FileName() As String
Get
If String.IsNullOrEmpty(_FileName) Then
Return "LookAndFeelSettings.save"
Else
Return _FileName
End If
End Get
Set(ByVal value As String)
_FileName = value
End Set
End Property
Private Sub Application_ApplicationExit(ByVal sender As Object, ByVal e As EventArgs)
SaveSettings()
End Sub
Private Sub SaveSettings()
Save(FileName)
End Sub
Private Sub RestoreSettings()
Load(FileName)
End Sub
Public Shared Sub Save(ByVal fileName As String)
Dim stream As FileStream
Dim settings As LookAndFeelSettings
Dim formatter As BinaryFormatter
settings = New LookAndFeelSettings()
settings.SkinName = UserLookAndFeel.Default.SkinName
settings.Style = UserLookAndFeel.Default.Style
settings.UseWindowsXPTheme = UserLookAndFeel.Default.UseWindowsXPTheme
stream = New FileStream(fileName, FileMode.Create)
Using stream
formatter = New BinaryFormatter()
formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
formatter.Serialize(stream, settings)
End Using
End Sub
Public Shared Sub Load(ByVal fileName As String)
If File.Exists(fileName) Then
Using stream As New FileStream(fileName, FileMode.Open)
Dim formatter As New BinaryFormatter()
formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
Dim settings As LookAndFeelSettings = TryCast(formatter.Deserialize(stream), LookAndFeelSettings)
If settings IsNot Nothing Then
UserLookAndFeel.Default.UseWindowsXPTheme = settings.UseWindowsXPTheme
UserLookAndFeel.Default.Style = settings.Style
UserLookAndFeel.Default.SkinName = settings.SkinName
End If
End Using
End If
End Sub
End Class
End Namespace