大佬教程收集整理的这篇文章主要介绍了[VB.NET]VB.net 读写ini的问题,希望好心人贡献下时间,帮忙解决下~~,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
VB.net 读写ini的问题,希望好心人贡献下时间,帮忙解决下~~ Imports Syste
m.Text ''声明 Inherits Syste
m.Window
s.Form
s.Form ''命名空间 Declare Function GetPrivateProfileInt Lib "kernel32 " Alias "GetPrivateProfileIntA " ( _ ByVal lpApplicationName As
String,_ ByVal lpKeyName As
String,_ ByVal nDefault As
Integer,_ ByVal lpFil
ename As
String) As
Integer Declare Function GetPrivateProfile
String Lib "kernel32 " Alias "GetPrivateProfile
StringA " ( _ ByVal lpApplicationName As
String,_ ByVal lpDefault As
String,_ ByVal lpReturned
String As
StringBuilder,_ ByVal nSize As
Integer,_ ByVal lpFil
ename As
String) As
Integer Declare Function WritePrivateProfile
String Lib "kernel32 " Alias "WritePrivateProfile
StringA " ( _ ByVal lpApplicationName As
String,_ ByVal lp
String As
String,_ ByVal lpFil
ename As
String) As
Integer Declare Function GetPrivateProfileSection Lib "kernel32 " Alias "GetPrivateProfileSectionA " ( _ ByVal lpAppName As
String,_ ByVal lpFil
ename As
String) As
Integer Declare Function WritePrivateProfileSection Lib "kernel32 " Alias "WritePrivateProfileSectionA " ( _ ByVal lpAppName As
String,_ ByVal lpFil
ename As
String) As
Integer Public Const
file_name = "./test.ini " ''设置路径 Private Sub Form1_Load(ByVal sender As Syste
m.Ob
ject,_ ByVal e As Syste
m.EventArgs) Handles MyBase.Load If (Syste
m.IO.File.Exists(
file_name)) Then Dim strCaption As
new StringBuilder(256) GetPrivateProfile
String( "Form ","Caption ","Default Caption ",_ strCaption,strCaption.Capacity,
file_name) Me.Text = strCaption.To
String() 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 Syste
m.ComponentMode
l.CancelEventArgs) Dim strCaption As
String = Me.Text WritePrivateProfile
String( "Form ",strCaption,
file_name) WritePrivateProfile
String( "Form ",Me.Width.To
String(),Me.Height.To
String(),Me.Left.To
String(),Me.Top.To
String(),
file_name) End Sub -------------------------------------- 上面主要用来记录Form的caption,还有大小位置 麻烦懂的好心人帮忙注释下,上面那5段的作用,还有下面的作用 如果我新加了一个textbox1,这个textbox1要能保存住里面的值,该怎么加上去,我不会哦 以后不懂读写ini的人看到这题应该都会了吧~~~希望好心人贡献下~~~~ __________________________________________________________________________
你的这段代码应该是来自VB6.0的,源码应该是日本人写的,我猜 GetPrivateProfileInt ''从ini文件中取得数值 GetPrivateProfile
String ’从ini文件中取得文字列 WritePrivateProfile
String ‘向ini文件中写入文字列 GetPrivateProfileSection ‘从被指定的SECTION中取得KEY ,值 WritePrivateProfileSection‘向初始化的SECTION中写入KEY ,值 __________________________________________________________________________ 这个建议直接使用IDE提供的本地资源设置功能. 它的说明就是: 使用 Visual
studio,
可以创建新的应用程序设置,并将它们绑定到窗体或窗体的控件上的属性,这样这些设置就会在运行时自动加载和保存。 关键词:应用程序设置,创建 __________________________________________________________________________ 把TextBox1的值写入ini文件,然后载入程序的时候再读取ini文件的对应的值到TextBox1就可以了 在OnClosing()子程序中添加: Dim s As
String=TextBox1.Text ''写入ini ''形如:TextBox1_Value=... WritePrivateProfile
String( "Form ","TextBox1_Value ",s,
file_name) __________________________________________________________________________ GetPrivateProfile
String( "Form ","textbox2 ",Nothing,
file_name) TextBox2.Text = strCaption.To
String() 解释下,在句子后面加上这一句,,,Nothing 可以设置为""也可以设置为vbnull
String strcaption.capacity自己看下注释是字节长度的意思,这句是GET,下面的是Write ---- Private Su
b TEXTBox2_TextChanged(ByVal sender As Syste
m.Ob
ject,ByVal e As Syste
m.EventArgs) Handles TextBox2.TextChanged WritePrivateProfile
String( "Form ",TextBox2.Text.To
String(),
file_name) End Sub __________________________________________________________________________ 没人给出如果读写Textbox的,,感谢第一位给的注释,汗~~最主要的是得~~Get~ __________________________________________________________________________ VB2005中有个My.Set
Tings命名空间,可以将设置保存在xml形式的config文件中,很方
便的啊 __________________________________________________________________________ 你去看看我的博客吧,里面有
很详细的说明
http://blog.csdn.net/zzy1254/archive/2007/05/22/1620308.aspx __________________________________________________________________________
大佬总结
以上是大佬教程为你收集整理的[VB.NET]VB.net 读写ini的问题,希望好心人贡献下时间,帮忙解决下~~全部内容,希望文章能够帮你解决[VB.NET]VB.net 读写ini的问题,希望好心人贡献下时间,帮忙解决下~~所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。