Category: Knowledge Base

How to get all logical drives on a system?

By calling a static method from System.Environment called GetLogicalDrives(). This returns a string array that you can easily iterate.Suppose you have a ListBox and a button: private void btnPopulate_Click(object sender, System.EventArgs e) { // Store in a string array string[] drives = Environment.GetLogicalDrives(); // Loop into the string array foreach(string strDrive in drives) { // Add […]

How do I stop the form from closing / How do I prompt the user to confirm the closing of the application when he presses the X button?

There are a few reasons why you may want this, in some applications, for example, you may want to ask the user if he wants to save the work before closing. You can easily do this by handling the form’s Closing event.In the following example we stop a form named Form1 from closing when clicking the ‘X’ shaped button: […]

Back To Top