Kod: Kodu kopyalamak için üzerine çift tıklayın!
Imports System.IO
Public Class Form1
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SaveSetting(Application.ProductName, Application.ProductName, "kayıt sayısı", kayitSayisi_Lbl.Text.ToString)
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
LstEkleTxt.Focus()
Call ListeYukle()
ListBox1.HorizontalScrollbar = True
End Sub
Public Sub ListeYukle()
ListBox1.Items.Clear()
Yukle = New IO.StreamReader(ListeYolVeDsyAdi, System.Text.Encoding.Default)
While (Yukle.Peek() > 0)
Me.ListBox1.Items.Add(Yukle.ReadLine)
kayitSayisi = kayitSayisi + 1
End While
Yukle.Close()
kayitSayisi_Lbl.Text = kayitSayisi
End Sub
Private Sub TxtOlarakSaklaBtn_Click(sender As System.Object, e As System.EventArgs) Handles TxtOlarakSaklaBtn.Click
Try
TextBox1.Text = ""
Yukle = New IO.StreamReader(ListeYolVeDsyAdi, System.Text.Encoding.Default)
While (Yukle.Peek() > 0)
TextBox1.Text = TextBox1.Text & ", " & Yukle.ReadLine
End While
Yukle.Close()
' Textboxtaki metni Sakla
My.Computer.FileSystem.WriteAllText(TextYolVeDsyAdi, TextBox1.Text, False, System.Text.Encoding.Default)
Catch exp As Exception
MessageBox.Show(exp.Message, "Hata oluştu..")
End Try
End Sub
Private Sub ListeAcBtn_Click(sender As System.Object, e As System.EventArgs) Handles ListeAcBtn.Click
On Error Resume Next
TxtSilBtn.PerformClick()
TextBox1.Clear()
TextBox1.Text = IO.File.ReadAllText(TextYolVeDsyAdi, System.Text.Encoding.Default)
End Sub
Private Sub DosyaAcBtn_Click(sender As System.Object, e As System.EventArgs) Handles DosyaAcBtn.Click
Try
Dim openDLG As New OpenFileDialog
openDLG.Filter = "Text Dosyaları (*.txt)|*.txt|Tüm Dosyalar (*.*)|*.*"
openDLG.InitialDirectory = DsyYolu
If openDLG.ShowDialog = DialogResult.OK Then
Dim dosya As New System.IO.StreamReader(openDLG.FileName, System.Text.Encoding.Default)
If openDLG.SafeFileName = "Liste.txt" Then
Yukle = New IO.StreamReader(ListeYolVeDsyAdi, System.Text.Encoding.Default)
While (Yukle.Peek() > 0)
Me.ListBox1.Items.Add(Yukle.ReadLine)
End While
Yukle.Close()
Exit Sub
End If
Dim str As String = dosya.ReadToEnd()
TextBox1.Text = str
dosya.Close()
End If
Catch exc As Exception
MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub ListeyeEkleBtn_Click(sender As System.Object, e As System.EventArgs) Handles ListeyeEkleBtn.Click
' LİSTEYE İSİM EKLEME
If LstEkleTxt.Text = Nothing Or LstEkleTxt.Text = "BURAYA BİR İSİM GİRİN" Then LstEkleTxt.Text = "BURAYA BİR İSİM GİRİN" : LstEkleTxt.SelectAll() : Exit Sub
ListBox1.Items.Add(LstEkleTxt.Text)
kayitSayisi = (ListBox1.Items.Count - 1) + 1
kayitSayisi_Lbl.Text = kayitSayisi
ListeSaklaBtn.Enabled = True
LstEkleTxt.Text = ""
End Sub
Private Sub TxtSilBtn_Click(sender As System.Object, e As System.EventArgs) Handles TxtSilBtn.Click
TextBox1.Text = Nothing
End Sub
Private Sub ListBox1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
On Error Resume Next
If e.KeyCode = Keys.Delete Then
Call SatirSil()
ListeSaklaBtn.Enabled = True
End If
If e.KeyCode = Keys.F12 Then
kayitSayisi_Lbl.Text = 0
kayitSayisi = 0
ListBox1.Items.Clear()
End If
If e.KeyCode = Keys.Escape Then
Dim dosyaBoyut As IO.FileInfo
dosyaBoyut = My.Computer.FileSystem.GetFileInfo(ListeYolVeDsyAdi)
If TextBox1.TextLength > 0 Then
TextBox1.Text = ""
TextBox1.Text = "Dosyamızın Boyutu : " & dosyaBoyut.Length & " bayt"
End If
End If
End Sub
Private Sub SatirSil()
On Error Resume Next
Dim secilecek, silinecek, LS As Integer
LS = Me.kayitSayisi_Lbl.Text.ToString()
If ListBox1.SelectedIndex <= ListBox1.Items.Count - 1 Then
silinecek = ListBox1.SelectedIndex
secilecek = silinecek - 1
Me.ListBox1.Items.RemoveAt(silinecek)
Me.ListBox1.SelectedIndex = secilecek
Me.kayitSayisi_Lbl.Text.ToString()
LS = LS - 1
Me.kayitSayisi_Lbl.Text = LS
End If
If ListBox1.SelectedIndex = -1 And ListBox1.Items.Count - 1 >= 0 Then
If silinecek = 0 Then
Me.ListBox1.SetSelected(secilecek + 1, True)
Exit Sub
End If
End If
If Me.kayitSayisi_Lbl.Text = -1 Then Me.kayitSayisi_Lbl.Text = 0
If Me.LblIndex.Text = -1 Then Me.LblIndex.Text = 0
End Sub
Private Sub ListBox1_MouseHover(sender As System.Object, e As System.EventArgs) Handles ListBox1.MouseHover
Dim tooltip As New ToolTip()
tooltip.SetToolTip(ListBox1, "ListBoxtan satır Silmek için DELETE tuşunu kullanın")
End Sub
Private Sub ListeSaklaBtn_Click(sender As System.Object, e As System.EventArgs) Handles ListeSaklaBtn.Click
' LİSTEYİ SAKLA
Dim dosyaBoyut As IO.FileInfo
dosyaBoyut = My.Computer.FileSystem.GetFileInfo(ListeYolVeDsyAdi)
If dosyaBoyut.Length <= 0 Then
Me.Text = "Dosya Boyut: " & dosyaBoyut.Length & " bayt"
Exit Sub
End If
Try
Dim Yaz As StreamWriter
Yaz = New StreamWriter(ListeYolVeDsyAdi, False, System.Text.Encoding.Default)
Dim i As Integer
For i = 0 To Me.ListBox1.Items.Count - 1
Yaz.WriteLine(ListBox1.Items.Item(i))
Next
Yaz.Close()
Catch exp As Exception
MessageBox.Show(exp.Message, "Hata oluştu.")
End Try
End Sub
Private Sub LstEkleTxt_MouseHover(sender As System.Object, e As System.EventArgs) Handles LstEkleTxt.MouseHover
Dim tooltip As New ToolTip()
tooltip.SetToolTip(LstEkleTxt, "Text kutusuna Ad ve Soyad girip" & vbCrLf & "Listeye Eklemek için Entere Basınızt")
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
On Error Resume Next
My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\Liste.txt")
My.Computer.FileSystem.CopyFile(Application.StartupPath & "\Liste_YDK.txt", Application.StartupPath & "\Liste.txt") '(kaynak dosya, hedef dosya)
kayitSayisi = 0
Call ListeYukle()
End Sub
Private Sub ListeyiYedekleBtn_Click(sender As System.Object, e As System.EventArgs) Handles ListeyiYedekleBtn.Click
Try
Dim Yaz As StreamWriter
Yaz = New StreamWriter(Application.StartupPath & "\Liste_YDK.txt", False, System.Text.Encoding.Default)
Dim i As Integer
For i = 0 To Me.ListBox1.Items.Count - 1
Yaz.WriteLine(ListBox1.Items.Item(i))
Next
Yaz.Close()
Catch exp As Exception
MessageBox.Show(exp.Message, "Hata oluştu.")
End Try
End Sub
Private Sub TxtOlarakSaklaBtn_MouseHover(sender As System.Object, e As System.EventArgs) Handles TxtOlarakSaklaBtn.MouseHover
Dim tooltip As New ToolTip()
tooltip.SetToolTip(TxtOlarakSaklaBtn, "Listeyi Text Olarak Sakla")
End Sub
Private Sub DosyaAcBtn_MouseHover(sender As System.Object, e As System.EventArgs) Handles DosyaAcBtn.MouseHover
Dim tooltip As New ToolTip()
tooltip.SetToolTip(DosyaAcBtn, "Liste ve text Dosyalarını gör")
End Sub
Private Sub ListeyiYedekleBtn_MouseHover(sender As System.Object, e As System.EventArgs) Handles ListeyiYedekleBtn.MouseHover
Dim tooltip As New ToolTip()
tooltip.SetToolTip(ListeyiYedekleBtn, "Listenin bir yedeğini Oluştur")
End Sub
Private Sub Button1_MouseHover(sender As System.Object, e As System.EventArgs) Handles Button1.MouseHover
Dim tooltip As New ToolTip()
tooltip.SetToolTip(Button1, "Yedek Listeden Yükle.")
End Sub
Private Sub ListeSaklaBtn_MouseHover(sender As System.Object, e As System.EventArgs) Handles ListeSaklaBtn.MouseHover
Dim tooltip As New ToolTip()
tooltip.SetToolTip(ListeSaklaBtn, "Listeye kayı ekledikten sonra sakla.")
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
On Error Resume Next
Me.LblIndex.Text = ListBox1.SelectedIndex
If ListBox1.Items.Count < kayitSayisi_Lbl.Text.ToString Then 'kayitSayisi_Lbl.Text.ToString
ListeSaklaBtn.Enabled = True
Else
ListeSaklaBtn.Enabled = False
End If
End Sub
End Class