Managing Files in C# - The Foundations (Page 2 of 5 )
Now that you've started Visual Studio, let's create our new project. It's quite straightforward that we opt for a new C# Windows Application. Once that's created, check out the way I've designed my form. The one and only main form is called frmMain and its sizes are the following: 415, 183. I've disabled the MaximizeBox and set its form border style to FixedSingle.

I have opted to write the entire code into the frmMain.cs, because this way we eliminate the need to have code snippets in both a separate C# code file and the form with the Windows Form Designer-generated code. All code is within one file in our case, and that's frmMain.cs. Oh, and don't forget to add two dialogs to our form: openFileDialog and saveFileDialog. This is also the way I named them.
Our project won't require any additional namespaces and/or libraries so we stick to the defaults.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
The name of the project is FileManager, thus the following class is created. By the way, keep in mind that I have intentionally left out the Windows Form Designer-generated code as well as the declarations of components' variables and their configurations. It's your job to configure them. Afterward, the IDE generates the code.
static class FileManager
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
}
}
As you can see from the above block of code, the application runs the frmMain() public method. It is going to be part of a public partial class. Additionally, as soon as the form is loaded and the components are initialized, we are going to hide the "unnecessary" components from the form and resize only the menu.
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
this.txtProperties.Hide();
this.btnHide.Hide();
this.lblNewFileName.Hide();
this.txtNewFileName.Hide();
this.btnGoRename.Hide();
this.btnCancel.Hide();
this.ClientSize = new System.Drawing.Size(145, 158);
}
}
Hide() conceals the control from the user. With the help of ClientSize(), we specify the new size for our frmMain (this refers to that). Now that we have built the basics of our project, we can move on by coding the components and discussing what each of them does. Now comes the real part. Everything that you find below is part of the partial class called frmMain (that's where the Win Form Designer generated code goes also).
Next: Copying, Moving, and Deleting >>
More C# Articles
More By Barzan "Tony" Antal