VB中怎样在启动窗体时自动加载图片
也就是在窗体启动时会把目录下的图片加载到窗体中。尽量说详细点……还有读、写INI文件的方法。先谢谢了……...
也就是在窗体启动时会把目录下的图片加载到窗体中。尽量说详细点……还有读、写INI文件的方法。先谢谢了……
展开
2个回答
展开全部
窗体启动时载入图片:
Private Sub Form_Load()
Me.Picture = LoadPicture( "路径+文件名")
End Sub
如果程序和图像文件在同一目录内可以改成:
Me.Picture = LoadPicture( App.Path & "\文件名")
读写INI文件的方法:
在工程中,新建一个模块,将如下代码粘贴进去!
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Sub WriteToIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
Dim buff As String * 128
buff = Value + Chr(0)
WritePrivateProfileString Section, Key, buff, FileName
End Sub
Public Function ReadFromIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As String
Dim i As Long
Dim buff As String * 128
GetPrivateProfileString Section, Key, "", buff, 128, FileName
i = InStr(buff, Chr(0))
ReadFromIni = Trim(Left(buff, i - 1))
End Function
在Form窗体代码某事件【比如:Form_Load()事件】 过程中,
’读取INI文件的例子皮拍
Dim p As String
p=ReadFromIni("路燃告羡径+INI文件名", "名称1", "名称2")
比如:p=ReadFromIni("d:\MusicPlayer.ini", "设置", "文件夹路径")
’写入INI文件的例子
WriteToIni "路径+INI文件名"友掘, "名称1", "名称2","字符串或者一个变量"
比如:
WriteToIni "d:\MusicPlayer.ini", "设置", "文件夹路径", "e:\mymusic"
或者:
dim f as string
f="e:\mymusic"
WriteToIni "d:\MusicPlayer.ini", "设置", "文件夹路径", f
Private Sub Form_Load()
Me.Picture = LoadPicture( "路径+文件名")
End Sub
如果程序和图像文件在同一目录内可以改成:
Me.Picture = LoadPicture( App.Path & "\文件名")
读写INI文件的方法:
在工程中,新建一个模块,将如下代码粘贴进去!
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Sub WriteToIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
Dim buff As String * 128
buff = Value + Chr(0)
WritePrivateProfileString Section, Key, buff, FileName
End Sub
Public Function ReadFromIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As String
Dim i As Long
Dim buff As String * 128
GetPrivateProfileString Section, Key, "", buff, 128, FileName
i = InStr(buff, Chr(0))
ReadFromIni = Trim(Left(buff, i - 1))
End Function
在Form窗体代码某事件【比如:Form_Load()事件】 过程中,
’读取INI文件的例子皮拍
Dim p As String
p=ReadFromIni("路燃告羡径+INI文件名", "名称1", "名称2")
比如:p=ReadFromIni("d:\MusicPlayer.ini", "设置", "文件夹路径")
’写入INI文件的例子
WriteToIni "路径+INI文件名"友掘, "名称1", "名称2","字符串或者一个变量"
比如:
WriteToIni "d:\MusicPlayer.ini", "设置", "文件夹路径", "e:\mymusic"
或者:
dim f as string
f="e:\mymusic"
WriteToIni "d:\MusicPlayer.ini", "设置", "文件夹路径", f
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询