├── README.md ├── LICENSE └── 7.1.cs /README.md: -------------------------------------------------------------------------------- 1 | # Windowsforms01 2 | Do you have the option of not using a visual studio?
3 | I don't want to use it. However, I would like to create an application!
4 | At the command prompt only 5 | 6 | I will do my best to create it using target:winexe. 7 | The following can create a windowsapp at the command prompt. 8 | [https://github.com/matahino/Windowsforms01/releases](https://github.com/matahino/Windowsforms01/releases/tag/C%231) 9 | 10 | 11 | 12 | Functions of this application
13 | Specify the address of a folder and view the folder there
14 | Sort by size using the sort function. 15 | 16 | ![スクリーンショット 2024-02-03 091108](https://github.com/matahino/Windowsforms01/assets/96413690/58018175-5d7e-4369-a9e4-5b786500f716) 17 | ![スクリーンショット 2024-02-03 091140](https://github.com/matahino/Windowsforms01/assets/96413690/2451749c-c628-401d-a907-8c547cb0e278) 18 | ![スクリーンショット 2024-02-03 091208](https://github.com/matahino/Windowsforms01/assets/96413690/fe1fe5b6-a967-4dd1-be50-ee7db3020f52) 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /7.1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Drawing; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Windows.Forms; 7 | 8 | namespace Tt 9 | { 10 | public class Form1 : Form 11 | { 12 | private Button myButton; 13 | private TextBox myTextBox; 14 | private ListBox myListBox; 15 | private Button mySortButton; 16 | private Button myDeleteButton; 17 | private string path; 18 | 19 | public Form1() 20 | { 21 | myButton = new Button 22 | { 23 | Size = new Size(100, 50), 24 | Location = new Point(200, 400), 25 | Text = "Click Me" 26 | }; 27 | myButton.Click += new EventHandler(MyButton_Click); 28 | 29 | mySortButton = new Button 30 | { 31 | Size = new Size(100, 50), 32 | Location = new Point(300, 400), 33 | Text = "Sort Me" 34 | }; 35 | mySortButton.Click += new EventHandler(MySortButton_Click); 36 | 37 | myDeleteButton = new Button 38 | { 39 | Size = new Size(100, 50), 40 | Location = new Point(400, 400), 41 | Text = "Delete" 42 | }; 43 | myDeleteButton.Click += new EventHandler(MyDeleteButton_Click); 44 | 45 | myTextBox = new TextBox 46 | { 47 | Size = new Size(300, 40), 48 | Location = new Point(100, 50) 49 | }; 50 | 51 | myListBox = new ListBox 52 | { 53 | Size = new Size(300, 300), 54 | Location = new Point(100, 100) 55 | }; 56 | myListBox.MouseDoubleClick += new MouseEventHandler(MyListBox_MouseDoubleClick); 57 | 58 | Text = "Folder Viewer"; 59 | ClientSize = new Size(600, 500); 60 | Controls.AddRange(new Control[] { myButton, mySortButton, myDeleteButton, myTextBox, myListBox }); 61 | } 62 | 63 | private void MyButton_Click(object sender, EventArgs e) 64 | { 65 | path = myTextBox.Text; 66 | if (Directory.Exists(path)) 67 | { 68 | string[] directories = Directory.GetDirectories(path); 69 | myListBox.Items.Clear(); 70 | foreach (string directory in directories) 71 | { 72 | myListBox.Items.Add(new DirectoryInfo(directory).Name); 73 | } 74 | } 75 | else 76 | { 77 | MessageBox.Show("Invalid path!"); 78 | } 79 | } 80 | 81 | private void MySortButton_Click(object sender, EventArgs e) 82 | { 83 | if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) 84 | { 85 | MessageBox.Show("Please specify a valid path."); 86 | return; 87 | } 88 | 89 | try 90 | { 91 | var sortedItems = myListBox.Items.Cast() 92 | .Select(item => new 93 | { 94 | Name = item, 95 | Size = GetDirectorySize(new DirectoryInfo(Path.Combine(path, item))) 96 | }) 97 | .OrderByDescending(item => item.Size) 98 | .Select(item => item.Name).ToList(); 99 | 100 | if (sortedItems.Count == 0) 101 | { 102 | MessageBox.Show("There are no items to sort."); 103 | return; 104 | } 105 | 106 | myListBox.Items.Clear(); 107 | foreach (var item in sortedItems) 108 | { 109 | myListBox.Items.Add(item); 110 | } 111 | } 112 | catch (Exception ex) 113 | { 114 | MessageBox.Show("An error has occurred:. " + ex.Message); 115 | } 116 | } 117 | 118 | private long GetDirectorySize(DirectoryInfo dirInfo) 119 | { 120 | long size = 0; 121 | FileInfo[] fileInfos; 122 | DirectoryInfo[] dirInfos; 123 | 124 | try 125 | { 126 | fileInfos = dirInfo.GetFiles(); 127 | dirInfos = dirInfo.GetDirectories(); 128 | } 129 | catch (UnauthorizedAccessException) 130 | { 131 | return size; // Skip directories to which you do not have access rights 132 | } 133 | 134 | foreach (var fileInfo in fileInfos) 135 | { 136 | size += fileInfo.Length; 137 | } 138 | 139 | foreach (var subDirInfo in dirInfos) 140 | { 141 | size += GetDirectorySize(subDirInfo); 142 | } 143 | 144 | return size; 145 | } 146 | 147 | private void MyListBox_MouseDoubleClick(object sender, MouseEventArgs e) 148 | { 149 | int index = myListBox.IndexFromPoint(e.Location); 150 | if (index != ListBox.NoMatches) 151 | { 152 | string dirPath = Path.Combine(path, myListBox.Items[index].ToString()); 153 | Process.Start(new ProcessStartInfo 154 | { 155 | FileName = dirPath, 156 | UseShellExecute = true, 157 | Verb = "open" 158 | }); 159 | } 160 | } 161 | 162 | private void MyDeleteButton_Click(object sender, EventArgs e) 163 | { 164 | if (myListBox.SelectedIndex == -1) 165 | { 166 | MessageBox.Show("Select the item to be deleted."); 167 | return; 168 | } 169 | 170 | string selectedItem = myListBox.SelectedItem.ToString(); 171 | string fullPath = Path.Combine(path, selectedItem); 172 | 173 | try 174 | { 175 | if (Directory.Exists(fullPath)) 176 | { 177 | Directory.Delete(fullPath, true); // true for recursive delete 178 | myListBox.Items.RemoveAt(myListBox.SelectedIndex); 179 | } 180 | else 181 | { 182 | MessageBox.Show("Directory to be deleted is not found."); 183 | } 184 | } 185 | catch (Exception ex) 186 | { 187 | MessageBox.Show("An error occurred while deleting:. " + ex.Message); 188 | } 189 | } 190 | } 191 | 192 | public class b 193 | { 194 | [STAThread] 195 | static void Main() 196 | { 197 | Application.EnableVisualStyles(); 198 | Application.SetCompatibleTextRenderingDefault(false); 199 | Application.Run(new Form1()); 200 | } 201 | } 202 | } 203 | --------------------------------------------------------------------------------