如何获取动态添加拼贴项目的标记

如何获取动态添加拼贴项目的标记

本文介绍了如何获取动态添加拼贴项目的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imports System.IO
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.TileItem
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Start()
        GetDrive()
        'tile()
        'CompInfo()
    End Sub
    Private Function GetSize(ByVal bt As Int64) As String
        If bt < 1024 Then
            Return bt.ToString() + " Bytes"
        End If
        Dim s As String
        Dim sz As Double = Convert.ToDouble(bt)
        If sz < 1048576.0 Then
            s = " KB"
            sz /= 1024.0
        ElseIf sz < 1073741824.0 Then
            s = " MB"
            sz /= 1048576.0
        ElseIf sz < 1099511627776.0 Then
            s = " GB"
            sz /= 1073741824.0
        Else
            s = " TB"
            sz /= 1099511627776.0
        End If
        If sz >= 100.0 Then
            Return Math.Truncate(sz).ToString("0") + s
        End If
        If sz >= 10.0 Then
            Return (Math.Truncate(sz * 10.0) / 10.0).ToString("0.0") + s
        End If
        Return (Math.Truncate(sz * 100.0) / 100.0).ToString("0.00") + s
    End Function

    Public Function CompInfo() As String
        GetSize(My.Computer.Info.AvailablePhysicalMemory)
        Return CompInfo
    End Function

    Private Sub ShowDirectory(ByVal dirInfo As DirectoryInfo, ByVal keepOffset As Boolean)
        If Not dirInfo.Exists Then
            Return
        Else
            MsgBox(dirInfo)
        End If
        '
        'Dim TileItem As New TileItem
        'TileItem.ItemSize = TileItemSize.Large
    End Sub
    Private Sub TileItemClick(ByVal sender As Object, ByVal e As EventArgs)

        ShowDirectory(CType(CType(sender, TileItem).Tag, DriveInfo).RootDirectory, False)
        'Dim TileItem As New TileItem
        'TileItem.ItemSize = TileItemSize.Large
    End Sub
    Private Function GetDrive()
        For Each Drive In My.Computer.FileSystem.Drives
            Dim DriveType As DriveType = Drive.DriveType
            Dim grp As TileGroup = GetDriveGroup(DriveType)
            Dim Tile As New TileItem
            Dim TileText1 As New TileItemElement
            TileText1.TextAlignment = TileItemContentAlignment.BottomRight
            Select Case (DriveType)
                Case DriveType.CDRom
                    Tile.ImageAlignment = TileItemContentAlignment.BottomLeft
                    Tile.Image = My.Resources.cd_48
                    If Not Drive.IsReady Then
                        Tile.Text = "<Size=+5>Empty " + Drive.Name + "</size>"
                    Else
                        Tile.Text = "<size=+5>" + Drive.VolumeLabel.ToString + "</size>"
                        TileText1.Text = "<Size=+4>Free Space:" + GetSize(Drive.TotalFreeSpace) & "<br>" & "Total Space" + GetSize(Drive.TotalSize) & ""
                        Tile.Elements.Add(TileText1)
                    End If
                    Tile.ItemSize = TileItemSize.Wide
                Case DriveType.Fixed
                    Tile.ImageAlignment = TileItemContentAlignment.BottomLeft
                    Tile.Image = My.Resources.hdd_48
                    Tile.Text = "<Size=+5>" + Drive.VolumeLabel.ToString & " (" & Drive.Name & ")" + "</size=+3>"
                    TileText1.Text = "<Size=+4>Free Space:" + GetSize(Drive.TotalFreeSpace) & "<br>" & "Total Space" + GetSize(Drive.TotalSize) & ""
                    Tile.Elements.Add(TileText1)
                    Tile.ItemSize = TileItemSize.Wide
                Case DriveType.Removable

                    Tile.ImageAlignment = TileItemContentAlignment.BottomLeft
                    Tile.Image = My.Resources.usb_connected_48
                    If Not Drive.IsReady Then
                        Tile.Text = "<Size=+5>Empty " + Drive.Name + "</size>"
                        Tile.Image = My.Resources.usb_disconnected_48
                    Else
                        Tile.Text = "<Size=+5>" + Drive.VolumeLabel.ToString & " (" & Drive.Name & ")" + "</size=+3>"
                        TileText1.Text = "<Size=+4>Free Space:" + GetSize(Drive.TotalFreeSpace) & "<br>" & "Total Space" + GetSize(Drive.TotalSize) & ""
                        Tile.Elements.Add(TileText1)
                    End If
                    Tile.ItemSize = TileItemSize.Wide
            End Select
            grp.Items.Add(Tile)
            AddHandler Tile.ItemClick, AddressOf Me.TileItemClick
        Next
        Return GetDrive
    End Function

    Private Function GetDriveGroup(ByVal DriveType As DriveType) As TileGroup
        Dim GroupName As String = DriveType.ToString
        For Each Group As TileGroup In TileControl1.Groups
            If Group.Name = GroupName Then
                Return Group
            End If
        Next

        Dim NewGroup As New TileGroup
        Select Case DriveType
            Case DriveType.CDRom
                NewGroup.Text = "CD/DVD"
            Case DriveType.Fixed
                NewGroup.Text = "Fixed Drives"
            Case DriveType.Network
                NewGroup.Text = "Network Drives"
            Case DriveType.Removable
                NewGroup.Text = "Removable Drives"
            Case DriveType.Ram
                NewGroup.Text = "RAM Drives"
            Case Else
                NewGroup.Text = "Other"
        End Select
        TileControl1.Groups.Add(NewGroup)
        NewGroup.Name = GroupName
        Return NewGroup
    End Function
End Class





NullReferenceException未处理

对象引用未设置为对象实例



我正在使用devexpress winform工具表单我正在使用tile控件组件



NullReferenceException was unhandled
Object reference not set to an instance of an object

I am using devexpress winform tool form which I am using tile control component

推荐答案

Private Function GetDrive()
      For Each Drive In My.Computer.FileSystem.Drives
          Dim DriveType As DriveType = Drive.DriveType
          Dim grp As TileGroup = GetDriveGroup(DriveType)
          Dim Tile As New TileItem
          Tile.Tag = Drive


这篇关于如何获取动态添加拼贴项目的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:37