標題:
[分享]
[VB2010] txt 簡易 讀 寫 視窗
[打印本頁]
作者:
mark15jill
時間:
2013-3-7 13:45
標題:
[VB2010] txt 簡易 讀 寫 視窗
預設目錄:D:\123.txt
[attach]14290[/attach]
有問題可以問...
此帖僅提供基本讀寫功能,並無提供關鍵字搜尋功能
Imports System.IO
'方法1
Public Class Form1
Dim lab As New Label
Dim bum1, bum2 As New Button
Dim te1, te2 As New TextBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me
.Controls.Add(lab)
.Height = 600
.Width = 800
.FormBorderStyle = Windows.Forms.FormBorderStyle.Fixed3D
With .Controls
.Add(te1) : .Add(te2) : .Add(bum1) : .Add(bum2)
End With
End With
With te1
.ScrollBars = ScrollBars.Both
.BorderStyle = BorderStyle.Fixed3D
.Width = (Me.Width - 40) / 2
.Height = Me.Height - 150
.Location = New Point(10, 100)
.Multiline = True
End With
With te2
.ScrollBars = ScrollBars.Both
.BorderStyle = BorderStyle.Fixed3D
.Width = (Me.Width - 40) / 2
.Height = Me.Height - 150
.Location = New Point(10 + te1.Width + te1.Location.X, 100)
.Multiline = True
End With
With bum1
.TextAlign = ContentAlignment.MiddleCenter
.Text = "寫"
.Width = 100
.Height = 40
.Location = New Point(((te1.Location.X + te1.Width) / 2) - 50, 50)
End With
With bum2
.TextAlign = ContentAlignment.MiddleCenter
.Text = "讀"
.Width = 100
.Height = 40
.Location = New Point((Me.Width - te2.Location.X - 10) + ((te2.Width + te2.Location.X) / 4), 50)
End With
With lab
.TextAlign = ContentAlignment.MiddleCenter
.Location = New Point((Me.Width / 2) - 100, 10)
.Width = 200
.Height = 25
.AutoSize = False
.BackColor = Color.Peru
.BorderStyle = BorderStyle.Fixed3D
.Text = "先寫後讀"
End With
AddHandler bum1.Click, AddressOf button1_Click
AddHandler bum2.Click, AddressOf button2_Click
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim kk1 As String
kk1 = te1.Text
Dim FileNum As Integer
Dim strTemp As String
FileNum = FreeFile()
FileOpen(FileNum, "D:\123.txt", OpenMode.Output)
strTemp = kk1
PrintLine(FileNum, strTemp)
FileClose(FileNum)
End Sub
Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim FileNum As Integer
Dim strTemp As String
FileNum = FreeFile()
FileOpen(FileNum, "D:\123.txt", OpenMode.Input)
Do Until EOF(FileNum)
te2.Text = LineInput(FileNum) & vbNewLine
Loop
FileClose(FileNum)
End Sub
End Class
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)