[VB.NET]VB.net 读写ini的问题,希望好心人贡献下时间,帮忙解决下~~

前端之家收集整理的这篇文章主要介绍了[VB.NET]VB.net 读写ini的问题,希望好心人贡献下时间,帮忙解决下~~前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
VB.net 读写ini的问题,希望好心人贡献下时间,帮忙解决下~~ Imports System.Text ''声明 Inherits System.Windows.Forms.Form ''命名空间 Declare Function GetPrivateProfileInt Lib "kernel32 " Alias "GetPrivateProfileIntA " ( _ ByVal lpApplicationName As String,_ ByVal lpKeyName As String,_ ByVal nDefault As Integer,_ ByVal lpFileName As String) As Integer Declare Function GetPrivateProfileString Lib "kernel32 " Alias "GetPrivateProfileStringA " ( _ ByVal lpApplicationName As String,_ ByVal lpDefault As String,_ ByVal lpReturnedString As StringBuilder,_ ByVal nSize As Integer,_ ByVal lpFileName As String) As Integer Declare Function WritePrivateProfileString Lib "kernel32 " Alias "WritePrivateProfileStringA " ( _ ByVal lpApplicationName As String,_ ByVal lpString As String,_ ByVal lpFileName As String) As Integer Declare Function GetPrivateProfileSection Lib "kernel32 " Alias "GetPrivateProfileSectionA " ( _ ByVal lpAppName As String,_ ByVal lpFileName As String) As Integer Declare Function WritePrivateProfileSection Lib "kernel32 " Alias "WritePrivateProfileSectionA " ( _ ByVal lpAppName As String,_ ByVal lpFileName As String) As Integer Public Const FILE_NAME = "./test.ini " ''设置路径 Private Sub Form1_Load(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles MyBase.Load If (System.IO.File.Exists(FILE_NAME)) Then Dim strCaption As New StringBuilder(256) GetPrivateProfileString( "Form ","Caption ","Default Caption ",_ strCaption,strCaption.Capacity,FILE_NAME) Me.Text = strCaption.ToString() Me.Width = GetPrivateProfileInt( "Form ","Width ",Me.Width,FILE_NAME) Me.Height = GetPrivateProfileInt( "Form ","Height ",Me.Height,FILE_NAME) Me.Left = GetPrivateProfileInt( "Form ","Left ",Me.Left,FILE_NAME) Me.Top = GetPrivateProfileInt( "Form ","Top ",Me.Top,FILE_NAME) End If End Sub Protected Overrides Sub OnClosing( _ ByVal e As System.ComponentModel.CancelEventArgs) Dim strCaption As String = Me.Text WritePrivateProfileString( "Form ",strCaption,FILE_NAME) WritePrivateProfileString( "Form ",Me.Width.ToString(),Me.Height.ToString(),Me.Left.ToString(),Me.Top.ToString(),FILE_NAME) End Sub -------------------------------------- 上面主要用来记录Form的caption,还有大小位置 麻烦懂的好心人帮忙注释下,上面那5段的作用,还有下面的作用 如果我新加了一个textBox1,这个textBox1要能保存住里面的值,该怎么加上去,我不会哦 以后不懂读写ini的人看到这题应该都会了吧~~~希望好心人贡献下~~~~ __________________________________________________________________________ 你的这段代码应该是来自VB6.0的,源码应该是日本人写的,我猜 GetPrivateProfileInt ''从ini文件中取得数值 GetPrivateProfileString ’从ini文件中取得文字列 WritePrivateProfileString ‘向ini文件中写入文字列 GetPrivateProfileSection ‘从被指定的SECTION中取得KEY ,值 WritePrivateProfileSection‘向初始化的SECTION中写入KEY ,值 __________________________________________________________________________ 这个建议直接使用IDE提供的本地资源设置功能. 它的说明就是: 使用 Visual Studio,可以创建新的应用程序设置,并将它们绑定到窗体或窗体的控件上的属性,这样这些设置就会在运行时自动加载和保存。 关键词:应用程序设置,创建 __________________________________________________________________________ 把TextBox1的值写入ini文件,然后载入程序的时候再读取ini文件的对应的值到TextBox1就可以了 在OnClosing()子程序中添加: Dim s As String=TextBox1.Text ''写入ini ''形如:TextBox1_Value=... WritePrivateProfileString( "Form ","TextBox1_Value ",s,FILE_NAME) __________________________________________________________________________ GetPrivateProfileString( "Form ","textBox2 ",Nothing,FILE_NAME) TextBox2.Text = strCaption.ToString() 解释下,在句子后面加上这一句,,,Nothing 可以设置为""也可以设置为vbnullstring strcaption.capacity自己看下注释是字节长度的意思,这句是GET,下面的是Write ---- Private Sub TextBox2_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles TextBox2.TextChanged WritePrivateProfileString( "Form ",TextBox2.Text.ToString(),FILE_NAME) End Sub __________________________________________________________________________ 没人给出如果读写TextBox的,,感谢第一位给的注释,汗~~最主要的是得~~Get~ __________________________________________________________________________ VB2005中有个My.Settings命名空间,可以将设置保存在xml形式的config文件中,很方便的啊 __________________________________________________________________________ 你去看看我的博客吧,里面有很详细的说明 http://blog.csdn.net/zzy1254/archive/2007/05/22/1620308.aspx __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/263820.html

猜你在找的VB相关文章