本文共 2062 字,大约阅读时间需要 6 分钟。
一.访问(清空)页面控件(C#)
private void InitPageCtr(Control control ) { foreach (Control ctr in control.Controls ) { //如果是 Pannel , GroupBox,继续再找 if (ctr is System.Windows.Forms.GroupBox || ctr is System.Windows.Forms.Panel) InitPageCtr(ctr); else { Console.WriteLine($"Name:{ctr.Name.ToUpper()};Type:{ctr.GetType().Name.ToUpper()}"); //控件名及类型 //switch (ctr.GetType().Name.ToUpper ()) //{ // case "TEXTBOX": // (ctr as TextBox).Text = ""; // break; // case "COMBOBOX": // (ctr as ComboBox).SelectedIndex = 0; // break; // default: // break; //} } } }
二.列举文件夹的文件名
private static void GetFileListOfFolder(string folder)
{ DirectoryInfo di = new DirectoryInfo(folder); DirectoryInfo[] arrDi = di.GetDirectories(); Console.WriteLine($"--------------------------Foler:{di.FullName}----------------------"); di.GetFiles().ToList().ForEach(o => { Console.WriteLine(o.FullName); }); arrDi.AsEnumerable().ToList().ForEach(o => { GetFileListOfFolder(o.FullName); }); }'Get the files in the folder (Include subfolder) Public rtnList_FilePathName As New List(Of String())() Public Function GetFilesInFolder(ByVal path As String) As List(Of String()) Dim fileInfo = New DirectoryInfo(path) ' For Each file In fileNames For Each file As FileInfo In fileInfo.GetFiles() rtnList_FilePathName.Add({file.FullName, If(String.IsNullOrEmpty(file.Extension), file.Name, file.Name.Replace(file.Extension, ""))}) Next Dim directories = Directory.GetDirectories(path) For Each dirpath In directories GetFilesInFolder(dirpath) Next Return rtnList_FilePathName End Function
转载地址:http://dsmdi.baihongyu.com/