vb点虐 ini类的简单介绍
在vb点虐 中怎么调用自定义类?
代码已测试。
10多年的龙华网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整龙华建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“龙华网站设计”,“龙华网站推广”以来,每个客户项目都认真落实执行。
一、测试需要的INI文件。名称为“setinfo.ini”,存放路径为你解决方案里“Bin“文件夹的”Debug“文件夹里。
内容:
[Location]
pnlTime.Location.X=787
pnlTime.Location.Y=0
[TopMost]
Top=True
二、操作INI文件的类。新建一个类,类中内容为:
Public Class Class1
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Int32, _
ByVal lpFileName As String _
) As Int32
End Class
三、界面代码:
Imports System.IO 'for path
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
getINI()
End Sub
Private Sub getINI()
Dim iniclass As New Class1 '
Dim myBf As String 'get set_info 开辟存储的内存
myBf = New String(CChar(""), 256)
Dim myFN As String '配置文件的文件路径
myFN = Path.Combine(My.Application.Info.DirectoryPath, "setinfo.ini")
Dim myAN As String 'Application_NAME,也是Section名称
myAN = Me.TextBox1.Text
Dim myKN As String 'KEY_NAME,关键字名称
myKN = Me.TextBox2.Text
Class1.GetPrivateProfileString(myAN, myKN, "", myBf, myBf.Length, myFN) '调用读取INI文件的操作
TextBox3.Text = Microsoft.VisualBasic.Left(myBf, InStr(myBf, Chr(0)) - 1) '截取有用部分,有必要
End Sub
End Class
四、测试截图如下
VB点虐 2005中到底怎么读取ini文件
用API吧
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
'读
Public Function GetINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As String
Dim Str As String = LSet(Str, 256)
GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)
Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)
End Function
'写
Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal WriteString As String, ByVal FileName As String) As Long
WriteINI = WritePrivateProfileString(Section, AppName, WriteString, FileName)
End Function
其中,Section是像[ip]那样的(填里面的就可以了),AppName是“=”前面的项名称,lpDefault是如果没有可用的值,就返回lpDefault,FileName是文件名,WriteString是要写入的值
你所希望的:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(GetINI("ip", "user_id", "", "D:\DataBase.ini"))
'返回sa
End Sub
vb点虐 如何读取ini文件定义的ForeColor颜色值
你好,我不知道你是用什么方法保存的,不过点虐 里的color有一个方法是Color.FromArgb 你可以这么做,dim
c
as
color=richtextbox1.ForeColor dim
colorstring
as
string=c.ToArgb().ToString
colorstring就是颜色的值(字符串)再把colorstring保存到ini文件加载颜色的时候,从ini里读取colorstring 具体是:dim
RtextColor
as
color=Color.FromArgb(cint(colorstring))richtextbox1.ForeColor
=RtextColor
分享名称:vb点虐 ini类的简单介绍
链接URL:http://azwzsj.com/article/ddjcsjs.html