Imports System.IO Imports System.Runtime.InteropServices Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents T As System.Windows.Forms.TreeView Friend WithEvents L As System.Windows.Forms.ListView Friend WithEvents ImageList1 As System.Windows.Forms.ImageList Friend WithEvents Rt As System.Windows.Forms.RichTextBox Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.Rt = New System.Windows.Forms.RichTextBox() Me.T = New System.Windows.Forms.TreeView() Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components) Me.L = New System.Windows.Forms.ListView() Me.SuspendLayout() ' 'Rt ' Me.Rt.AllowDrop = True Me.Rt.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(178, Byte)) Me.Rt.HideSelection = False Me.Rt.Location = New System.Drawing.Point(8, 8) Me.Rt.Name = "Rt" Me.Rt.RightToLeft = System.Windows.Forms.RightToLeft.Yes Me.Rt.Size = New System.Drawing.Size(544, 104) Me.Rt.TabIndex = 0 Me.Rt.Text = "" ' 'T ' Me.T.AllowDrop = True Me.T.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(178, Byte)) Me.T.HideSelection = False Me.T.ImageList = Me.ImageList1 Me.T.Location = New System.Drawing.Point(8, 120) Me.T.Name = "T" Me.T.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("محتويات القرص الصلب"), New System.Windows.Forms.TreeNode("محتويات محرّك الإسطوانات"), New System.Windows.Forms.TreeNode("العناصر المسقطة")}) Me.T.RightToLeft = System.Windows.Forms.RightToLeft.No Me.T.Size = New System.Drawing.Size(176, 226) Me.T.TabIndex = 4 ' 'ImageList1 ' Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer) Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent ' 'L ' Me.L.AllowDrop = True Me.L.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(178, Byte)) Me.L.HideSelection = False Me.L.LargeImageList = Me.ImageList1 Me.L.Location = New System.Drawing.Point(192, 120) Me.L.Name = "L" Me.L.RightToLeft = System.Windows.Forms.RightToLeft.No Me.L.Size = New System.Drawing.Size(360, 226) Me.L.SmallImageList = Me.ImageList1 Me.L.TabIndex = 6 Me.L.View = System.Windows.Forms.View.List ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(560, 354) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.L, Me.T, Me.Rt}) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.Name = "Form1" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub FrmEnter_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Drv() As String = Directory.GetLogicalDrives Dim Fs As New Scripting.FileSystemObject() Dim C As Integer With T.Nodes(0).Nodes T.Nodes(0).Tag = 1 For C = 0 To Drv.GetUpperBound(0) If Fs.GetDrive(Drv(C)).DriveType <> Scripting.DriveTypeConst.CDRom Then ExplorOneLevel(.Add(Drv(C))) Else T.Nodes(1).Tag = 1 ExplorOneLevel(T.Nodes(1).Nodes.Add(Drv(C))) End If Next End With End Sub Sub ExplorOneLevel(ByVal N As TreeNode) On Error GoTo LineExit Dim P As String = N.FullPath Dim St As Integer = InStr(P, "\") P = Mid(P, St + 1, Len(P) - St).Replace("\\", "\") Dim Dr() As String = Directory.GetDirectories(P) Array.Sort(Dr) N.Tag = 1 Dim C As Integer With N.Nodes For C = 0 To Dr.GetUpperBound(0) .Add(Path.GetFileName(Dr(C))) Next End With LineExit: End Sub Private Sub T_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles T.BeforeExpand If e.Node.Tag = 1 Then Dim C As Integer With e.Node For C = 0 To .GetNodeCount(False) - 1 If .Nodes(C).Tag <> 1 Then ExplorOneLevel(.Nodes(C)) End If Next End With End If End Sub Private Sub T_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles T.AfterSelect Try Select Case e.Node.Text Case T.Nodes(1).Text, T.Nodes(0).Text L.Clear() Dim C As Integer For c = 0 To e.Node.GetNodeCount(False) - 1 L.Items.Add(e.Node.Nodes(c).Text).ImageIndex = 0 Next Case Else L.Clear() Dim P As String = e.Node.FullPath Dim St As Integer = InStr(P, "\") P = Mid(P, St + 1, Len(P) - St).Replace("\\", "\") Dim F() As String = Directory.GetDirectories(P) Array.Sort(F) Dim C As Integer L.BeginUpdate() For C = 0 To F.GetUpperBound(0) L.Items.Add(Path.GetFileName(F(C))).ImageIndex = 0 Next F = Directory.GetFiles(P) Array.Sort(F) For C = 0 To F.GetUpperBound(0) L.Items.Add(Path.GetFileName(F(C))).ImageIndex = 1 Next L.EndUpdate() End Select Catch X As Exception End Try End Sub Private Sub L_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles L.DoubleClick OpenFolder() End Sub ' لاحظ أنّ هذا الحدث يستجيب للأدوات الثلاثة معا Private Sub TheDragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles T.DragEnter, L.DragEnter, Rt.DragEnter If e.Data.GetDataPresent(GetType(TreeNode)) OrElse e.Data.GetDataPresent(DataFormats.Text) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub Private Sub T_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles T.ItemDrag T.DoDragDrop(CType(e.Item, TreeNode).Clone, DragDropEffects.Copy) End Sub Sub OpenFolder() If L.SelectedItems.Count > 0 AndAlso L.SelectedItems(0).ImageIndex = 0 Then Dim S As String = L.SelectedItems(0).Text With T.SelectedNode Dim C As Integer For C = 0 To .GetNodeCount(False) - 1 If .Nodes(C).Text = S Then T.SelectedNode = .Nodes(C) Exit Sub End If Next End With End If End Sub Private Sub L_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles L.KeyPress If e.KeyChar = Chr(Keys.Enter) Then OpenFolder() End If End Sub Private Sub Rt_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Rt.MouseDown If e.Button = MouseButtons.Left Then If Rt.SelectedText <> "" Then Rt.DoDragDrop(Rt.SelectedText, DragDropEffects.Copy) End If End If End Sub Private Sub L_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles L.ItemDrag L.DoDragDrop(CType(e.Item, ListViewItem).Text, DragDropEffects.Copy) End Sub Private Sub T_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles T.DragDrop If e.Data.GetDataPresent(GetType(TreeNode)) Then T.Nodes(2).Nodes.Add(e.Data.GetData(GetType(TreeNode))) T.Nodes(2).Expand() ElseIf e.Data.GetDataPresent(DataFormats.Text) Then T.Nodes(2).Nodes.Add(e.Data.GetData(DataFormats.Text)) T.Nodes(2).Expand() End If End Sub Private Sub L_DragDrop(ByVal sender As Object, ByVal e As _ DragEventArgs) Handles L.DragDrop If e.Data.GetDataPresent(GetType(TreeNode)) Then Dim N As TreeNode N = CType(e.Data.GetData(GetType(TreeNode)), TreeNode) L.Items.Add(N.Text) L.EnsureVisible(L.Items.Count - 1) ElseIf e.Data.GetDataPresent(DataFormats.Text) Then L.Items.Add(e.Data.GetData(DataFormats.Text)) L.EnsureVisible(L.Items.Count - 1) End If End Sub Private Sub Rt_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Rt.DragDrop If e.Data.GetDataPresent(GetType(TreeNode)) Then ' تغيير موضع الكتابة إلى الموضع الذي سيتمّ الإسقاط عليه ' لاحظ أنّنا نحتاج أولا لتحويل النقطة ' من إحداثيّات الشاشة إلى إحداثيّات مربّع النصّ المنسّق Rt.SelectionStart = Rt.GetCharIndexFromPosition(Rt.PointToClient(New Point(e.X, e.Y))) Dim N As TreeNode = CType(e.Data.GetData(GetType(TreeNode)), TreeNode) Rt.SelectedText += N.Text TraceNodes(N) ElseIf e.Data.GetDataPresent(DataFormats.Text) Then Rt.SelectionStart = Rt.GetCharIndexFromPosition(Rt.PointToClient(New Point(e.X, e.Y))) Rt.SelectedText += (e.Data.GetData(DataFormats.Text)) End If End Sub Sub TraceNodes(ByRef N As TreeNode) Dim C, Idnt As Integer Idnt = Rt.SelectionIndent + 16 For C = 0 To N.GetNodeCount(False) - 1 Rt.SelectedText = vbLf & N.Nodes(C).Text Rt.SelectionIndent = Idnt TraceNodes(N.Nodes(C)) Next End Sub End Class