?? frmsave.vb
字號(hào):
Imports System.IO
Imports System.Xml.Serialization
'//串行化為XML文檔
Imports System.Xml
Imports System.Runtime.Serialization.Formatters.Binary
'//串行化為二進(jìn)制文檔
Imports System.Runtime.Serialization.Formatters.Soap
'//串行化為Soap文檔
Imports Microsoft.VisualBasic
Public Class frmSave
Inherits System.Windows.Forms.Form
#Region " Windows 窗體設(shè)計(jì)器生成的代碼 "
Public Sub New()
MyBase.New()
'該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。
InitializeComponent()
'在 InitializeComponent() 調(diào)用之后添加任何初始化
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 窗體設(shè)計(jì)器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下過程是 Windows 窗體設(shè)計(jì)器所必需的
'可以使用 Windows 窗體設(shè)計(jì)器修改此過程。
'不要使用代碼編輯器修改它。
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 = "保存配置選項(xiàng)"
'
'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 = "還原默認(rèn)值"
'
'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 = "默認(rèn)配置,速度快,有一定的加密效果,但只適合與.NET平臺(tái)不易于交流可讀性差"
'
'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 = "保存為二進(jìn)制文檔"
'
'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 = "保存設(shè)置"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Dim infofile As String
<Serializable()> Public Class 配置信息
Private _info As String
Public Property 保存設(shè)置() 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.保存設(shè)置 = "Binary"
ElseIf Option2.Checked = True Then
form.infofile = "XML"
info.保存設(shè)置 = "XML"
ElseIf Option3.Checked = True Then
form.infofile = "Soap"
info.保存設(shè)置 = "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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -