用API吧
創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、長白網(wǎng)絡(luò)推廣、微信平臺小程序開發(fā)、長白網(wǎng)絡(luò)營銷、長白企業(yè)策劃、長白品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供長白建站搭建服務(wù),24小時服務(wù)熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com
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,F(xiàn)ileName是文件名,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
1,對于INI文件,可以當(dāng)做像TXT文件一樣來進(jìn)行讀取和寫入。
2,先把整個文件度出來,然后找到相應(yīng)行刪除(拋棄)以后,再重新寫入文件。
Public?Class?Form1
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
Dim?MyStr?As?String?=?""
Dim?AllStr?As?String?=?""
'獲取一個可用的文件號
Dim?MyFileNum?As?Integer?=?FreeFile()
'打開指定的文件,進(jìn)行讀取操作
FileOpen(MyFileNum,?"C:\My.ini",?OpenMode.Input)
Do?While?Not?EOF(MyFileNum)
'讀取一行
MyStr?=?LineInput(MyFileNum)
If?MyStr??"b=2"?Then
If?AllStr?=?""?Then
AllStr?=?AllStr??MyStr
Else
AllStr?=?AllStr??vbCrLf??MyStr
End?If
End?If
Loop
FileClose(MyFileNum)???'關(guān)閉文件
'寫文件
Dim?MyStream?As?New?System.IO.FileStream("C:\My.ini",?IO.FileMode.Create)
Dim?MyWriter?As?New?System.IO.StreamWriter(MyStream,?System.Text.Encoding.UTF8)
MyWriter.WriteLine(AllStr)
MyWriter.Flush()
MyWriter.Close()
MyStream.Close()
End?Sub
End?Class
你好,我不知道你是用什么方法保存的,不過點虐 里的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
以下是我的辦法:OK!
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 Integer, ByVal lpFileName As String) As Integer
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
寫:
WritePrivateProfileString("存儲", "賬號", textbox1, Application.StartupPath "\song.ini")
讀:
dim s as string
s = string(255," ")
GetPrivateProfileString("存儲", "賬號", s, s.Length, Application.StartupPath + "\song.ini")
textbox1 =s