Social Icons

Saturday, 29 March 2014

C# Working of Dialog Boxes



Dialog boxes are used to gather input from users. You can create your own dialog boxes or use the built-in dialog boxes, such as the FolderBrowserDialog and FontDialog.Here i am going to show you how to create dialog boxes and use common built-in dialog boxes in your programs.


 Download the interface Download


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace dialogs
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void openToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            // working of openFileDialog
            openFileDialog1.Filter = "Jpeg Image|*.jpg|Bitmap|*.gif";
            openFileDialog1.Title = "Open an Image File";
            openFileDialog1.FileName = "";
            openFileDialog1.ShowDialog();
            pictureBox1.ImageLocation = openFileDialog1.FileName;
        }

        private void fontToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // working of fontDialog
            fontDialog1.ShowDialog();
            label1.Font = fontDialog1.Font;
        }

        private void colorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // working of colorDialog
            colorDialog1.ShowDialog();
            label1.ForeColor = colorDialog1.Color;
        }

        private void textBox1_MouseClick(object sender, MouseEventArgs e)
        {
            // for reset the textbox text on mouse click
            textBox1.Text = "";
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            // which we write in textbox will show on label
            if (textBox1.Text != "")
            label1.Text = textBox1.Text;
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // working of saveFileDialog
            try
            {
                saveFileDialog1.FileName = "*.jpg";
                saveFileDialog1.ShowDialog();
                pictureBox1.Image.Save(saveFileDialog1.FileName);
            }
            catch
            {
                MessageBox.Show(" Image not save");
            }
        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            // working folderBrowserDialog
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                // The user selected a folder and pressed the OK button.             
              textBox2.Text = folderBrowserDialog1.SelectedPath;
              foreach (string file in Directory.GetFiles(textBox2.Text))
               {
                   //Add file in comboBox.
                   comboBox1.Items.Add(file);
               }           
            }          
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // set images in pictureBox which is selected from combobox
            pictureBox1.ImageLocation = comboBox1.Text;
        } 
    }
}


Click here to Download 

1 comment: