Results 1 to 1 of 1

Thread: Notez - For Fast Use of the Clipboard

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2017
    Posts
    6

    Lightbulb Notez - For Fast Use of the Clipboard

    There are many occasions where I need to copy and paste many strings one after another and I got tired of doing it all manually so I created a small app to help gather those strings. No one else may can use it, but it helps me out tremendously! Hopefully someone can find a use for the app.


    Name:  notez.png
Views: 697
Size:  4.3 KB
    not much to look at :P


    vb.net Code:
    1. Imports System.IO
    2.  
    3. Public Class FrmMain
    4.     Dim nl As String = Environment.NewLine
    5.     Dim tf As String = "C:\ProgramData\Notez\temp.txt"
    6.     Dim td As String = "C:\ProgramData\Notez\"
    7.     Dim t As New List(Of String)()
    8.     Dim mb As String = "Left"
    9.  
    10.     Private Sub TextBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.DoubleClick
    11.         TextBox1.Text &= nl & System.Windows.Forms.Clipboard.GetText
    12.     End Sub
    13.  
    14.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    15.         Me.TopMost = True
    16.         Me.Top = My.Computer.Screen.WorkingArea.Height - Me.Height
    17.         Me.Left = 0
    18.         If File.Exists(tf) Then
    19.             Dim s() As String = File.ReadAllText(tf).Split(nl)
    20.             For Each a As String In s
    21.                 If a <> "" And a <> " " And a <> "    " And a <> nl And a <> vbNullChar And a <> vbNullString Then
    22.                     LstNotes.Items.Add(a)
    23.                     t.Add(a)
    24.                 End If
    25.             Next
    26.         End If
    27.     End Sub
    28.  
    29.     Private Sub ListBox1_RightClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LstNotes.MouseDown
    30.         If e.Button = MouseButtons.Right Then
    31.             mb = "Right"
    32.             If LstNotes.Items.Count > 0 Then
    33.                 Try
    34.                     Dim i As Integer = LstNotes.IndexFromPoint(e.X, e.Y)
    35.                     Dim d As Integer = LstNotes.SelectedIndex
    36.                     If i <> d Then
    37.                         LstNotes.SelectedIndex = LstNotes.IndexFromPoint(e.X, e.Y)
    38.                         If LstNotes.SelectedItems.Count > 0 Then
    39.                             LstNotes.Items.RemoveAt(LstNotes.SelectedIndex)
    40.                         End If
    41.                     Else
    42.                         LstNotes.Items.RemoveAt(LstNotes.SelectedIndex)
    43.                     End If
    44.                 Catch ex As Exception
    45.                     Try
    46.                         LstNotes.Items.RemoveAt(LstNotes.SelectedIndex)
    47.                     Catch ex2 As Exception
    48.                         CMSave.Show(PointToScreen(e.Location))
    49.                     End Try
    50.                 End Try
    51.             Else
    52.                 LstNotes.SelectedIndex = LstNotes.IndexFromPoint(e.X, e.Y)
    53.                 If LstNotes.SelectedItems.Count > 0 Then
    54.                     LstNotes.Items.RemoveAt(LstNotes.SelectedIndex)
    55.                 End If
    56.             End If
    57.         Else
    58.             mb = "Left"
    59.         End If
    60.     End Sub
    61.  
    62.     Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstNotes.DoubleClick
    63.         placest()
    64.     End Sub
    65.  
    66.     Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstNotes.SelectedIndexChanged
    67.         If LstNotes.SelectedItems.Count > 0 Then
    68.             If mb = "Left" Then
    69.                 Dim found As Boolean = False
    70.                 For Each t As String In LstNotes.Items
    71.                     If t.ToString = System.Windows.Forms.Clipboard.GetText() Then
    72.                         found = True
    73.                     End If
    74.                 Next
    75.                 If found = False Then
    76.                     Dim result As Integer = MessageBox.Show("Copy clipboard without saving string?", "Save String?", MessageBoxButtons.YesNo)
    77.                     If result = DialogResult.Yes Then
    78.                         copyst()
    79.                     Else
    80.                         placest()
    81.                         copyst()
    82.                     End If
    83.                 Else
    84.                     copyst()
    85.                 End If
    86.             Else
    87.             End If
    88.         End If
    89.         mb = "Left"
    90.     End Sub
    91.  
    92.     Private Sub placest()
    93.         Dim s As String = System.Windows.Forms.Clipboard.GetText()
    94.         LstNotes.Items.Add(s)
    95.         t.Add(s)
    96.     End Sub
    97.  
    98.     Private Sub copyst()
    99.         If LstNotes.SelectedItems.Count.ToString > 0 Then
    100.             Try
    101.                 System.Windows.Forms.Clipboard.SetText(LstNotes.SelectedItem.ToString)
    102.             Catch ex As Exception
    103.  
    104.             End Try
    105.         End If
    106.     End Sub
    107.  
    108.     Private Sub BtnRenew_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BtnRenew.Click
    109.         CMSave.Show(PointToScreen(e.Location))
    110.     End Sub
    111.  
    112.     Private Sub BtnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAccept.Click
    113.         Dim s As String = TxtMore.Text
    114.         If TxtMore.Text <> "" Then
    115.             LstNotes.Items.Add(s)
    116.             t.Add(s)
    117.             TxtMore.Clear()
    118.             TxtMore.Focus()
    119.         End If
    120.     End Sub
    121.  
    122.     Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
    123.         If LstNotes.Items.Count = 0 Then
    124.             t.Clear()
    125.         Else
    126.             LstNotes.Items.Clear()
    127.         End If
    128.     End Sub
    129.  
    130.     Private Sub FrmMain_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    131.         TxtMore.Top = BtnRenew.Height
    132.         TxtMore.Left = 0
    133.         TxtMore.Width = Me.Width - 15
    134.         TxtMore.Height = SplitContainer1.Panel1.Height - BtnRenew.Height
    135.         LstNotes.Top = SplitContainer1.Panel2.Top
    136.         LstNotes.Height = SplitContainer1.Panel2.Height - 2
    137.     End Sub
    138.  
    139.     Private Sub RefreshToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshToolStripMenuItem.Click
    140.         LstNotes.Items.Clear()
    141.         For Each Str As String In t
    142.             LstNotes.Items.Add(Str)
    143.         Next
    144.     End Sub
    145.  
    146.     Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
    147.         Dim s As SaveFileDialog = New SaveFileDialog()
    148.         s.Filter = "TXT Files|*.txt"
    149.         If s.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    150.             If s.FileName.Contains(".txt") Then
    151.                 Dim t As String = Nothing
    152.                 Dim c As Integer = LstNotes.Items.Count
    153.                 Dim i As Integer = 0
    154.                 For Each q As String In LstNotes.Items
    155.                     i = i + 1
    156.                     If i = c Then
    157.                         If t <> "" Then
    158.                             t &= q
    159.                         End If
    160.                     Else
    161.                         If t <> "" Then
    162.                             t &= q & nl
    163.                         End If
    164.                     End If
    165.                 Next
    166.                 If File.Exists(s.FileName) Then
    167.                     Dim result As Integer = MessageBox.Show("Overwrite Existing?", "Save File", MessageBoxButtons.YesNoCancel)
    168.                     If result = DialogResult.Yes Then
    169.                         Try
    170.                             File.Delete(s.FileName)
    171.                             File.WriteAllText(s.FileName, t)
    172.                         Catch ex As Exception
    173.                             MsgBox("File in use.", MsgBoxStyle.Exclamation, "Error")
    174.                         End Try
    175.                     End If
    176.                 End If
    177.             End If
    178.         End If
    179.         s.Dispose()
    180.     End Sub
    181.  
    182.     Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    183.         Dim s As OpenFileDialog = New OpenFileDialog()
    184.         s.Filter = "TXT Files|*.txt"
    185.         If s.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    186.             If s.FileName.ToString.ToUpper.Contains("TXT") Then
    187.             Else
    188.                 MsgBox("Not a TXT file.", MsgBoxStyle.Exclamation, "Error")
    189.             End If
    190.             Dim a() As String = File.ReadAllText(s.FileName).Split(nl)
    191.             LstNotes.Items.Clear()
    192.             t.Clear()
    193.             For Each st As String In a
    194.                 If st <> "" And st <> " " And st <> nl Then
    195.                     LstNotes.Items.Add(st)
    196.                     t.Add(st)
    197.                 End If
    198.             Next
    199.         End If
    200.         s.Dispose()
    201.     End Sub
    202.  
    203.     Private Sub writetemp()
    204.         Dim c As Integer = LstNotes.Items.Count
    205.         Dim i As Integer = 0
    206.         Dim s As String = Nothing
    207.         For Each t As String In LstNotes.Items
    208.             i = i + 1
    209.             If i = c Then
    210.                 If t <> "" Then
    211.                     s &= t
    212.                 End If
    213.             Else
    214.                 If t <> "" Then
    215.                     s &= t & nl
    216.                 End If
    217.             End If
    218.         Next
    219.         If Directory.Exists(td) = False Then
    220.             Directory.CreateDirectory(td)
    221.         End If
    222.         File.WriteAllText(tf, s)
    223.     End Sub
    224.  
    225.     Private Sub FrmMain_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    226.         If File.Exists(tf) Then
    227.             File.Delete(tf)
    228.             writetemp()
    229.         Else
    230.             writetemp()
    231.         End If
    232.     End Sub
    233.  
    234.     Private Sub AutoCollectToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AutoCollectToolStripMenuItem.Click
    235.         If TmrCollect.Enabled = False Then
    236.             TmrCollect.Start()
    237.             AutoCollectToolStripMenuItem.Font = New Drawing.Font("Segoe UI", 9, FontStyle.Regular)
    238.         Else
    239.             TmrCollect.Stop()
    240.             AutoCollectToolStripMenuItem.Font = New Drawing.Font("Segoe UI", 9, FontStyle.Strikeout)
    241.         End If
    242.     End Sub
    243.  
    244.     Private Sub TmrCollect_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrCollect.Tick
    245.         Try
    246.             Dim a As String = System.Windows.Forms.Clipboard.GetText(TextDataFormat.Text)
    247.             Dim got As Boolean = False
    248.             For Each s As String In LstNotes.Items
    249.                 If s = a Then
    250.                     got = True
    251.                 End If
    252.             Next
    253.             If got = False Then
    254.                 LstNotes.Items.Add(a)
    255.                 t.Add(a)
    256.             End If
    257.         Catch
    258.         End Try
    259.     End Sub
    260.  
    261.     Private Sub TopMostToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TopMostToolStripMenuItem.Click
    262.         If Me.TopMost = True Then
    263.             Me.TopMost = False
    264.             TopMostToolStripMenuItem.Font = New Drawing.Font("Segoe UI", 9, FontStyle.Strikeout)
    265.         Else
    266.             Me.TopMost = True
    267.             TopMostToolStripMenuItem.Font = New Drawing.Font("Segoe UI", 9, FontStyle.Regular)
    268.         End If
    269.     End Sub
    270. End Class
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width