Thursday 22 March 2012

List All Files in specified Drive or Folder








Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'make a reference to a directory
        Dim dir As New System.IO.DirectoryInfo("c:\")
        Dim dir1 As System.IO.FileInfo() = dir.GetFiles()
        Dim directory As System.IO.FileInfo
        'list the names of all files in the specified directory or Drive
        For Each directory In dir1
            ListBox1.Items.Add(directory)
        Next
    End Sub

List All Folders in specified Drive or Folder



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'make a reference to a directory
        Dim dir As New System.IO.DirectoryInfo("c:\")
        Dim dir1 As System.IO.DirectoryInfo() = dir.GetDirectories()
        Dim directory As System.IO.DirectoryInfo
        'list the names of all folders in the specified drive or Directory
        For Each directory In dir1
            ListBox1.Items.Add(directory)
        Next
    End Sub

Friday 3 February 2012

Drag Text from another Program


Need 1 TextBox  and set AllowDrop property of TextBox1  to True.

Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub

Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
        TextBox1.Text = e.Data.GetData(DataFormats.Text).ToString
    End Sub

Drag Content from one TextBox and Drop to another


Need 2 TextBox for doing this program and Set AllowDrop property of TextBox2  to True.
       
Private Sub TextBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
        TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Move)
    End Sub

Private Sub TextBox2_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
        TextBox2.Text &= e.Data.GetData(DataFormats.Text).ToString
        TextBox1.Text = ""
    End Sub

Private Sub TextBox2_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            e.Effect = DragDropEffects.Move
        End If
    End Sub