如何将VB表单的当前状态保存在计算机文件中,以便在用户再次运行它时可以轻松访问它? [英] How do i save my VB form current status in a computer file so I can easily access it when the user run it again??

查看:89
本文介绍了如何将VB表单的当前状态保存在计算机文件中,以便在用户再次运行它时可以轻松访问它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,
我需要保存的东西是

复选框(如果已标记)
和仅具有整数值的文本框

Guys,
the things i need to save is,

checkbox (if marked or not)
and textbox with interger values only

推荐答案

这很简单:

也添加此

This is so easy:

also add this

Imports System.Xml.Serialization
Imports System.IO

使用此代码保存课程:

    Shared Sub SerializeObject(Of T)(ByVal Obj As T, ByVal FileName As String)
        Dim Serializer As New XmlSerializer(GetType(T))
        Using Fs As New FileStream(FileName, FileMode.OpenOrCreate)
            Serializer.Serialize(Fs, Obj)
        End Using
    End Sub
    Shared Function DeserializeObject(Of T)(ByVal FileName As String) As T
        Dim Deserializer As New XmlSerializer(GetType(T))
        Dim FileStream As New FileStream(FileName, FileMode.Open)
        Dim MyRectangle As T = CType(Deserializer.Deserialize(FileStream), T)
        FileStream.Close()
        FileStream.Dispose()
        Return MyRectangle
    End Function

您只能保存自己的类,该类仅由字符串,整数,字节数,颜色等组成,并且

You can only save you own class which only consist strings integers lists bytes colors etc and 

请参阅:

<Serializable()>
Class File
    Public FileName As String
    Public Data As String
End Class

,您可以通过给定的功能保存和加载它:

and you can save and load it by given functions:

        SerializeObject(Of File)(New File, "abc.bbbbbb")
        Dim p As New File
        p = DeserializeObject(Of File)("abc.bbbbbb")

您可以创建任何类型的课程并保存

You can create any type of class and save it


这篇关于如何将VB表单的当前状态保存在计算机文件中,以便在用户再次运行它时可以轻松访问它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆