[英]Auto load TabControl from settings.ini file
I want when start form auto load TabControl TabPages from in ini file settings with WebBrowser1.我想在使用 WebBrowser1 的 ini 文件设置中启动表单时自动加载 TabControl TabPages。 I added image to below.我在下面添加了图像。
settings.ini file设置.ini文件
[site1]
name=Google
url=https://www.google.com
[site2]
name=Yahoo
url=https://www.yahoo.com
clsINI class code clsINI 类代码
Public Class clsIni
' API functions
Private Declare Ansi Function GetPrivateProfileString _
Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As System.Text.StringBuilder, _
ByVal nSize As Integer, ByVal lpFileName As String) _
As Integer
Private Declare Ansi Function WritePrivateProfileString _
Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Integer
Private Declare Ansi Function GetPrivateProfileInt _
Lib "kernel32.dll" Alias "GetPrivateProfileIntA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal nDefault As Integer, _
ByVal lpFileName As String) As Integer
Private Declare Ansi Function FlushPrivateProfileString _
Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As Integer, _
ByVal lpKeyName As Integer, ByVal lpString As Integer, _
ByVal lpFileName As String) As Integer
Dim strFilename As String
' Constructor, accepting a filename
Public Sub New(ByVal Filename As String)
strFilename = Filename
End Sub
' Read-only filename property
ReadOnly Property FileName() As String
Get
Return strFilename
End Get
End Property
Public Function GetString(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As String) As String
' Returns a string from your INI file
Dim intCharCount As Integer
Dim objResult As New System.Text.StringBuilder(256)
intCharCount = GetPrivateProfileString(Section, Key, [Default], objResult, objResult.Capacity, strFilename)
If intCharCount > 0 Then
GetString = Left(objResult.ToString, intCharCount)
Else
GetString = ""
End If
End Function
Public Function GetInteger(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As Integer) As Integer
' Returns an integer from your INI file
Return GetPrivateProfileInt(Section, Key, _
[Default], strFilename)
End Function
Public Function GetBoolean(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As Boolean) As Boolean
' Returns a boolean from your INI file
Return (GetPrivateProfileInt(Section, Key, _
CInt([Default]), strFilename) = 1)
End Function
Public Sub WriteString(ByVal Section As String, _
ByVal Key As String, ByVal Value As String)
' Writes a string to your INI file
WritePrivateProfileString(Section, Key, Value, strFilename)
Flush()
End Sub
Public Sub WriteInteger(ByVal Section As String, _
ByVal Key As String, ByVal Value As Integer)
' Writes an integer to your INI file
WriteString(Section, Key, CStr(Value))
Flush()
End Sub
Public Sub WriteBoolean(ByVal Section As String, _
ByVal Key As String, ByVal Value As Boolean)
' Writes a boolean to your INI file
WriteString(Section, Key, CStr(CInt(Value)))
Flush()
End Sub
Private Sub Flush()
' Stores all the cached changes to your INI file
FlushPrivateProfileString(0, 0, 0, strFilename)
End Sub
End Class
It's new tabcontrol code but without loop, i couldn't make it here.这是新的 tabcontrol 代码,但没有循环,我无法在这里完成。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tb As TabControl = New TabControl
Dim page1 As TabPage = New TabPage
tb.TabPages.Add(page1)
Me.Controls.Add(tb)
tb.Dock = DockStyle.Fill
End Sub
End Class
And i want like this, help me please.. like this我想要这样,请帮帮我..像这样
Ok i found solution for question...好的,我找到了问题的解决方案...
Click for clsINI reference单击以获取 clsINI 参考
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim LoadSettings As New clsIni("C:\settings.ini")
Dim sites As String
Dim url As String
Dim array() As Integer = {1, 2, 3}
Dim tb As TabControl = New TabControl
For i As Integer = 1 To array.Length - 1
sites = LoadSettings.GetString("site" & i, "name", "")
url = LoadSettings.GetString("site" & i, "url", "")
Dim page As TabPage = New TabPage
Dim browser As WebBrowser = New WebBrowser
tb.TabPages.Add(page)
page.Text = sites
Me.Controls.Add(tb)
tb.Dock = DockStyle.Fill
page.Controls.Add(browser)
browser.Navigate(url)
browser.Dock = DockStyle.Fill
Next
End Sub
End Class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.