[英]VB Show File/Folder Names
I am coding a programm that will run some batch files if they're selected by the user. 我正在编写一个程序,如果用户选择了一些批处理文件,它将运行这些批处理文件。
Each batch has its own folder in a specific "resources" folder. 每个批次在特定的“资源”文件夹中都有自己的文件夹。
I am looping through that folder to create checkboxes and labels. 我正在遍历该文件夹以创建复选框和标签。 Everything's working fine, but I don't want the label to have the whole path - I just want to display the foldername.
一切工作正常,但是我不希望标签具有完整的路径-我只想显示文件夹名称。
CODE : 代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim BatchFolder As IEnumerable = Directory.EnumerateFileSystemEntries(appPath & "/resources")
Dim totalNumber As Integer = Directory.GetDirectories(appPath & "/resources").Length
Dim i As Integer = 1
For Each dir As String In BatchFolder
Dim Label As New Label()
Label.Name = "Lb_" & dir
Label.Text = dir & ".bat"
Label.AutoSize = True
Label.Visible = True
Label.Location = New Point(55, 4 + 25 * i)
Dim CustomCheckbox As New Bunifu.Framework.UI.BunifuCheckbox()
CustomCheckbox.Visible = True
CustomCheckbox.Name = "CB_" & dir
CustomCheckbox.Checked = False
CustomCheckbox.Location = New Point(35, 25 * i)
CustomCheckbox.CheckedOnColor = Color.FromArgb(12, 106, 255)
Panel5.Controls.Add(Label)
Panel5.Controls.Add(CustomCheckbox)
i = i + 1
Next
Label21.Text = totalNumber
End Sub
This is how it looks: 它是这样的:
You can do it like this : 您可以这样做:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim BatchFolder As IEnumerable = Directory.EnumerateFileSystemEntries(appPath & "\resources")
Dim totalNumber As Integer = Directory.GetDirectories(appPath & "\resources").Length
Dim i As Integer = 1
For Each dir As String In BatchFolder
Dim Label As New Label()
dir = dir.Substring(dir.LastIndexOf("\") + 1)
Label.Name = "Lb_" & dir
Label.Text = dir & ".bat"
Label.AutoSize = True
Label.Visible = True
Label.Location = New Point(55, 4 + 25 * i)
Dim CustomCheckbox As New Bunifu.Framework.UI.BunifuCheckbox()
CustomCheckbox.Visible = True
CustomCheckbox.Name = "CB_" & dir
CustomCheckbox.Checked = False
CustomCheckbox.Location = New Point(35, 25 * i)
CustomCheckbox.CheckedOnColor = Color.FromArgb(12, 106, 255)
Panel5.Controls.Add(Label)
Panel5.Controls.Add(CustomCheckbox)
i = i + 1
Next
Label21.Text = totalNumber
End Sub
Hope it will help you :) 希望它能对您有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.