Posts

Showing posts from January, 2014

Add images in ListView (C#)

Image
We'll develop an application in which we'll get all images from a directory and add those images in a ListView. Open visual studio and create new " Windows Form Application " project. Go to Toolbox and drag and drop a ListView. Change name of that ListView to " imageListView ". Double at form and it'll navigate you to its load event. Now add following code in form load event. private void Form1_Load(object sender, EventArgs e) {     ImageList imageList = new ImageList();     // Clear imageList and imageListView     this.imageListView.Items.Clear();                 // Get directory info     DirectoryInfo dir = new DirectoryInfo(@"D:\Images");     // Read all files in directory     foreach (FileInfo file in dir.GetFiles())     {         try         {             imageList.Images.Add(Image.FromFile(file.FullName));         }         catch         {             Console.WriteLine("This is not an image file");

Resize and Save Multiple Images in C#

Image
We'll develop an application in which user can select multiple images by " OpenFileDialog " and copy those images to specific directory after resizing it. Open visual studio and create new " Windows Form Application " project. Go to Toolbox and drag a button. Change name of button to " FileUploadBtn ". Change text of button to " Upload & Resize Images ". Now double click at that button and add following code in its click event private void FileUploadBtn_Click(object sender, EventArgs e) {     OpenFileDialog openFileDialog = new OpenFileDialog();     //Add filter, if you want to allow all extenssions just remove it.     openFileDialog.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" + "All files (*.*)|*.*";     // Set multiselect true for slecting multiple files     openFileDialog.Multiselect = true;                // Show open file dialog and check if Open button is pressed.     if (openFil

Select & copy multiple files

Image
We are going to create an application in which we'll select multiple files by " OpenFileDialog " and copy those files to specific directory. Open visual studio and create new " Windows Form Application " project. Go to Toolbox and drag a button. Change name of button to " FileUploadBtn ". Change text of button to " Upload Files ". Now double click at that button and add following code in its click event. private void FileUploadBtn_Click(object sender, EventArgs e) {     OpenFileDialog openFileDialog = new OpenFileDialog();     //Add filter, if you want to allow all extenssions just remove it.     openFileDialog.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" + "All files (*.*)|*.*";     // Set multiselect true for slecting multiple files     openFileDialog.Multiselect = true;                // Show open file dialog and check if Open button is pressed.     if (openFileDialog.ShowDialog() == Di

Add button & its click event programmatically in C#

Image
We are going to create an application in which we'll add button in its click event programmatically. You just have to create a new object of " Button " format it (location, name, text, size etc), assign a click event, add it to the form and declare and initialize that click event. Open visual studio and create new " Windows Form Application " project. Double click at form and you will be in that form's " Form1_Load " event code. Now add following code in you  private void Form1_Load(object sender, EventArgs e) {       Button MyBtn = new Button();       // Button formation and other setting       MyBtn.Location = new System.Drawing.Point(100, 100);       MyBtn.Name = "MyButton";       MyBtn.Size = new System.Drawing.Size(75, 23);       MyBtn.TabIndex = 0;       MyBtn.Text = "My Button";       MyBtn.UseVisualStyleBackColor = true;       // Set button click event       MyBtn.Click += new EventHandler(Button_C