史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   [使用版本VB2008]使用INI檔儲存程式最後狀態 (http://forum.slime.com.tw/thread275424.html)

魔術王子 2014-02-05 07:46 PM

[使用版本VB2008]使用INI檔儲存程式最後狀態
 
大部分程式都是將資訊儲存在登錄檔,但小弟則是傾向存成INI檔
https://imagizer.imageshack.us/v2/720x464q90/191/2ozt.jpg
https://imagizer.imageshack.us/v2/720x464q90/543/ea8a.jpg
程式結束後,就會出現INI檔
https://imagizer.imageshack.us/v2/720x299q90/856/sewh.jpg
引用:

作者: 元件
PHP 語法:

   Private Sub InitializeComponent()
        
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        
Me.ToolStrip1 = New System.Windows.Forms.ToolStrip
        Me
.WebBrowser1 = New System.Windows.Forms.WebBrowser
        Me
.ToolStripTextBox1 = New System.Windows.Forms.ToolStripTextBox
        Me
.ToolStripButton1 = New System.Windows.Forms.ToolStripButton
        Me
.ToolStripSplitButton1 = New System.Windows.Forms.ToolStripSplitButton
        Me
.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
        Me
.ToolStripMenuItem2 = New System.Windows.Forms.ToolStripMenuItem
        Me
.ToolStripMenuItem3 = New System.Windows.Forms.ToolStripMenuItem
        Me
.ToolStrip1.SuspendLayout()
        
Me.SuspendLayout()
        
'
        '
ToolStrip1
        
'
        Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripSplitButton1, Me.ToolStripTextBox1, Me.ToolStripButton1})
        Me.ToolStrip1.Location = New System.Drawing.Point(0, 0)
        Me.ToolStrip1.Name = "ToolStrip1"
        Me.ToolStrip1.Size = New System.Drawing.Size(1292, 25)
        Me.ToolStrip1.TabIndex = 0
        Me.ToolStrip1.Text = "ToolStrip1"
        '
        'WebBrowser1
        '
        
Me.WebBrowser1.Dock System.Windows.Forms.DockStyle.Fill
        Me
.WebBrowser1.Location = New System.Drawing.Point(025)
        
Me.WebBrowser1.MinimumSize = New System.Drawing.Size(2020)
        
Me.WebBrowser1.Name "WebBrowser1"
        
Me.WebBrowser1.Size = New System.Drawing.Size(1292762)
        
Me.WebBrowser1.TabIndex 1
        
'
        '
ToolStripTextBox1
        
'
        Me.ToolStripTextBox1.Name = "ToolStripTextBox1"
        Me.ToolStripTextBox1.Size = New System.Drawing.Size(500, 25)
        '
        'ToolStripButton1
        '
        
Me.ToolStripButton1.DisplayStyle System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me
.ToolStripButton1.Image CType(resources.GetObject("ToolStripButton1.Image"), System.Drawing.Image)
        
Me.ToolStripButton1.ImageTransparentColor System.Drawing.Color.Magenta
        Me
.ToolStripButton1.Name "ToolStripButton1"
        
Me.ToolStripButton1.Size = New System.Drawing.Size(2322)
        
Me.ToolStripButton1.Text "ToolStripButton1"
        '
        '
ToolStripSplitButton1
        
'
        Me.ToolStripSplitButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me.ToolStripSplitButton1.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem1, Me.ToolStripMenuItem2, Me.ToolStripMenuItem3})
        Me.ToolStripSplitButton1.Image = CType(resources.GetObject("ToolStripSplitButton1.Image"), System.Drawing.Image)
        Me.ToolStripSplitButton1.ImageTransparentColor = System.Drawing.Color.Magenta
        Me.ToolStripSplitButton1.Name = "ToolStripSplitButton1"
        Me.ToolStripSplitButton1.Size = New System.Drawing.Size(32, 22)
        Me.ToolStripSplitButton1.Text = "ToolStripSplitButton1"
        '
        'ToolStripMenuItem1
        '
        
Me.ToolStripMenuItem1.Name "ToolStripMenuItem1"
        
Me.ToolStripMenuItem1.Size = New System.Drawing.Size(19622)
        
Me.ToolStripMenuItem1.Text "MSN"
        '
        '
ToolStripMenuItem2
        
'
        Me.ToolStripMenuItem2.Name = "ToolStripMenuItem2"
        Me.ToolStripMenuItem2.Size = New System.Drawing.Size(196, 22)
        Me.ToolStripMenuItem2.Text = "史萊姆論壇"
        '
        'ToolStripMenuItem3
        '
        
Me.ToolStripMenuItem3.Name "ToolStripMenuItem3"
        
Me.ToolStripMenuItem3.Size = New System.Drawing.Size(19622)
        
Me.ToolStripMenuItem3.Text "中央氣象局全球資訊網"
        '
        '
Form1
        
'
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(1292, 787)
        Me.Controls.Add(Me.WebBrowser1)
        Me.Controls.Add(Me.ToolStrip1)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Form1"
        Me.ToolStrip1.ResumeLayout(False)
        Me.ToolStrip1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents ToolStrip1 As System.Windows.Forms.ToolStrip
    Friend WithEvents WebBrowser1 As System.Windows.Forms.WebBrowser
    Friend WithEvents ToolStripTextBox1 As System.Windows.Forms.ToolStripTextBox
    Friend WithEvents ToolStripButton1 As System.Windows.Forms.ToolStripButton
    Friend WithEvents ToolStripSplitButton1 As System.Windows.Forms.ToolStripSplitButton
    Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ToolStripMenuItem2 As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ToolStripMenuItem3 As System.Windows.Forms.ToolStripMenuItem 


引用:

作者: 程式碼
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
PHP 語法:

Public Class Form1
    
Public Declare Function GetPrivateProfileString Lib "kernel32" _
 Alias 
"GetPrivateProfileStringA" _
 
<MarshalAs(UnmanagedType.LPStr)> ByVal lpApplicationName As String_
 
<MarshalAs(UnmanagedType.LPStr)> ByVal lpKeyName As String_
 
<MarshalAs(UnmanagedType.LPStr)> ByVal lpDefault As String_
 
<MarshalAs(UnmanagedType.LPStr)> ByVal lpReturnedString As StringBuilder_
 ByVal nSize 
As UInt32_
 
<MarshalAs(UnmanagedType.LPStr)> ByVal lpFileName As String) As UInt32
    
Public Declare Function WritePrivateProfileString Lib "kernel32" _
     Alias 
"WritePrivateProfileStringA" _
     
<MarshalAs(UnmanagedType.LPStr)> ByVal lpApplicationName As String_
     
<MarshalAs(UnmanagedType.LPStr)> ByVal lpKeyName As String_
     
<MarshalAs(UnmanagedType.LPStr)> ByVal lpReturnedString As StringBuilder_
     
<MarshalAs(UnmanagedType.LPStr)> ByVal lpFileName As String) As UInt32

    
Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load
        Dim sSection 
As String "Url"
        
Dim sKey As String "Default"
        
Dim sKeyValue As New StringBuilder(512)
        
Dim nSize As UInt32 Convert.ToUInt32(512)
        
Dim sinifilename As String My.Computer.FileSystem.CurrentDirectory "\QuitSaveINI.ini"
        
ToolStripTextBox1.Text My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main""Start Page"Nothing)
        
GetPrivateProfileString(sSectionsKey""sKeyValuenSizesinifilename)
        If 
sKeyValue.ToString <> "" Then ToolStripTextBox1.Text sKeyValue.ToString
        WebBrowser1
.Navigate(ToolStripTextBox1.Text)
    
End Sub

    
Private Sub Form1_FormClosed(ByVal sender As System.ObjectByVal e As System.Windows.Forms.FormClosedEventArgsHandles MyBase.FormClosed
        Dim lReturnLen 
As UInt32
        Dim sSection 
As String "Url"
        
Dim sKey As String "Default"
        
Dim sKeyValue As New StringBuilder(512)
        
Dim nSize As UInt32 Convert.ToUInt32(512)
        
Dim sinifilename As String My.Computer.FileSystem.CurrentDirectory "\QuitSaveINI.ini"
        
sKeyValue sKeyValue.Append(ToolStripTextBox1.Text)
        
lReturnLen WritePrivateProfileString(sSectionsKeysKeyValuesinifilename)
    
End Sub

    
Private Sub ToolStripButton1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ToolStripButton1.Click
        WebBrowser1
.Navigate(ToolStripTextBox1.Text)
    
End Sub

    
Private Sub ToolStripSplitButton1_ButtonClick(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ToolStripSplitButton1.ButtonClick
        ToolStripTextBox1
.Text My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main""Start Page"Nothing)
        
ToolStripButton1_Click(sendere)
    
End Sub

    
Private Sub ToolStripMenuItem1_Click_1(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ToolStripMenuItem1.Click
        ToolStripTextBox1
.Text "http://tw.msn.com/"
        
ToolStripButton1_Click(sendere)
    
End Sub

    
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ToolStripMenuItem2.Click
        ToolStripTextBox1
.Text "http://forum.slime.com.tw"
        
ToolStripButton1_Click(sendere)
    
End Sub

    
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ToolStripMenuItem3.Click
        ToolStripTextBox1
.Text "http://www.cwb.gov.tw/"
        
ToolStripButton1_Click(sendere)
    
End Sub
End 
Class 




所有時間均為台北時間。現在的時間是 05:08 AM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1