📄 frmsave.vb
字号:
Imports System.IO
Imports System.Xml.Serialization
'//串行化为XML文档
Imports System.Xml
Imports System.Runtime.Serialization.Formatters.Binary
'//串行化为二进制文档
Imports System.Runtime.Serialization.Formatters.Soap
'//串行化为Soap文档
Imports Microsoft.VisualBasic
Public Class frmSave
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
Public Sub New(ByVal _infofile As String)
MyBase.New()
InitializeComponent()
'//不能少
infofile = _infofile
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Option3 As System.Windows.Forms.RadioButton
Friend WithEvents Option1 As System.Windows.Forms.RadioButton
Friend WithEvents Option2 As System.Windows.Forms.RadioButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmSave))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button2 = New System.Windows.Forms.Button
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Option3 = New System.Windows.Forms.RadioButton
Me.Option1 = New System.Windows.Forms.RadioButton
Me.Option2 = New System.Windows.Forms.RadioButton
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Label3)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.Option3)
Me.GroupBox1.Controls.Add(Me.Option1)
Me.GroupBox1.Controls.Add(Me.Option2)
Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(344, 240)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "保存配置选项"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(248, 200)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 7
Me.Button2.Text = "确定"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(160, 144)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(176, 40)
Me.Label3.TabIndex = 6
Me.Label3.Text = "可读性好,无加密,使用于Web传输"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(160, 88)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(168, 40)
Me.Label2.TabIndex = 5
Me.Label2.Text = "可读性好,无加密,使用于Web传输"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(152, 200)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 4
Me.Button1.Text = "还原默认值"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(160, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(176, 48)
Me.Label1.TabIndex = 3
Me.Label1.Text = "默认配置,速度快,有一定的加密效果,但只适合与.NET平台不易于交流可读性差"
'
'Option3
'
Me.Option3.Location = New System.Drawing.Point(16, 152)
Me.Option3.Name = "Option3"
Me.Option3.Size = New System.Drawing.Size(120, 24)
Me.Option3.TabIndex = 2
Me.Option3.Text = "保存为Soap文档"
'
'Option1
'
Me.Option1.Location = New System.Drawing.Point(16, 40)
Me.Option1.Name = "Option1"
Me.Option1.Size = New System.Drawing.Size(128, 24)
Me.Option1.TabIndex = 1
Me.Option1.Text = "保存为二进制文档"
'
'Option2
'
Me.Option2.Location = New System.Drawing.Point(16, 96)
Me.Option2.Name = "Option2"
Me.Option2.Size = New System.Drawing.Size(120, 24)
Me.Option2.TabIndex = 0
Me.Option2.Text = "保存为XML文档"
'
'frmSave
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
Me.ClientSize = New System.Drawing.Size(360, 254)
Me.Controls.Add(Me.GroupBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmSave"
Me.Text = "保存设置"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Dim infofile As String
<Serializable()> Public Class 配置信息
Private _info As String
Public Property 保存设置() As String
Get
Return _info
End Get
Set(ByVal Value As String)
_info = Value
End Set
End Property
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim form As New Form1
Dim info As New 配置信息
Dim ser As New SerializationBinary
Dim filename As String = Application.StartupPath & "\save\配置文件.ini"
If Option1.Checked = True Then
Form.infofile = "Binary"
info.保存设置 = "Binary"
ElseIf Option2.Checked = True Then
form.infofile = "XML"
info.保存设置 = "XML"
ElseIf Option3.Checked = True Then
form.infofile = "Soap"
info.保存设置 = "Soap"
End If
ser.SerializeIt(filename, info)
form.ischange = True
Form1.ActiveForm.Close()
End Sub
Public Class SerializationBinary
Public Sub SerializeIt(ByVal filename As String, ByVal info As Object)
Dim formatter As New BinaryFormatter
'Dim info As 配置信息
Dim stream As FileStream = File.Create(filename)
formatter.Serialize(stream, info)
stream.Close()
End Sub
Public Function DeserialiaeIt(ByVal filename As String)
Dim stream As FileStream = File.OpenRead(filename)
Dim formatter As New BinaryFormatter
Dim info As 配置信息
info = CType(formatter.Deserialize(stream), 配置信息)
stream.Close()
Return info
End Function
End Class
Private Sub frmSave_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If infofile = "Binary" Then
Option1.Checked = True
ElseIf infofile = "XML" Then
Option2.Checked = True
ElseIf infofile = "Soap" Then
Option3.Checked = True
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -