gunsmokingman Posted April 21, 2009 Share Posted April 21, 2009 This is a simple demo of Vb.net Treeview control. What this does is uses the the Treeview and list all active drives on the computer. This then adds a node for file system, drive type,drive size, drive free, drive used. It also adds two tooltips that list the percent free and percentused.Public Class Form1 Const GB = 1073741824 Const MB = 1048576 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim ND As TreeNode ND = TreeView1.Nodes.Add(String.Format(My.Computer.Name)) DiskInfo() End Sub Private Sub DiskInfo() For Each Drv In My.Computer.FileSystem.Drives If Drv.IsReady Then ' Disk Size Dim St = "", S1 = "" If Drv.TotalSize < GB Then St = " MB" S1 = FormatNumber(Drv.TotalSize / MB, 2) Else St = " GB" S1 = FormatNumber(Drv.TotalSize / GB, 2) End If If Len(S1) = 4 Then S1 = "00" & S1 If Len(S1) = 5 Then S1 = "0" & S1 ' Disk Free Dim F1 = Drv.TotalFreeSpace, F2 = "", F3 = "", Ft = "" If F1 < GB Then Ft = " MB" F2 = FormatNumber(F1 / MB, 2) Else Ft = " GB" F2 = FormatNumber(F1 / GB, 2) End If If Len(F2) = 4 Then F2 = "00" & F2 If Len(F2) = 5 Then F2 = "0" & F2 F3 = "Percent Free : " & FormatPercent(F1 / Drv.TotalSize, 2) ' Disk Used Dim U1 = Drv.TotalSize - Drv.TotalFreeSpace, U2 = "", U3 = "", Ut = "" If U1 < GB Then Ut = " MB" U2 = FormatNumber(U1 / MB, 2) Else Ut = " GB" U2 = FormatNumber(U1 / GB, 2) End If If Len(U2) = 4 Then U2 = "00" & U2 If Len(U2) = 5 Then U2 = "0" & U2 U3 = "Percent Used : " & FormatPercent(U1 / Drv.TotalSize, 2) Dim node As TreeNode node = TreeView1.Nodes.Add(String.Format(Drv.Name & Drv.VolumeLabel)) node.Nodes.Add(String.Format("File " & Drv.DriveFormat)) Dim Dtype = "" Select Case Drv.DriveType Case IO.DriveType.Unknown : Dtype = "Unknown Drive Type" Case IO.DriveType.NoRootDirectory : Dtype = "No Root Directory Drive" Case IO.DriveType.Removable : Dtype = "Removable Drive" Case IO.DriveType.Fixed : Dtype = "Hard Drive" Case IO.DriveType.Network : Dtype = "Network Drive" Case IO.DriveType.CDRom : Dtype = "Optical Drive" Case IO.DriveType.Ram : Dtype = "Ram Drive" End Select Dim N As TreeNode N = node.Nodes.Add(String.Format("Type " & Dtype)) N.ForeColor = Color.FromArgb(1, 32, 96, 147) Dim N1 As TreeNode N1 = node.Nodes.Add(String.Format("Size " & S1 & St)) N1.ForeColor = Color.FromArgb(1, 32, 179, 131) Dim N2 As TreeNode N2 = node.Nodes.Add(String.Format("Free " & F2 & Ft)) N2.ForeColor = Color.FromArgb(1, 32, 131, 179) N2.ToolTipText = F3 Dim N3 As TreeNode N3 = node.Nodes.Add(String.Format("Used " & U2 & Ut)) N3.ForeColor = Color.FromArgb(1, 227, 121, 68) N3.ToolTipText = U3 End If Next End SubEnd ClassSource Code Link to comment Share on other sites More sharing options...
Doggie Posted April 25, 2009 Share Posted April 25, 2009 Good example Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now