Color DialogBox , SaveFileDialogBox,OpenFileDialogBox,FontDialogBox in Windows Forms Application c#

Color Dialog , SaveFileDialog,OpenFileDialog,FontDialog in C#:







ColorDialog box:


ColorDialog displays a color selection window. By using the ColorDialog, you can enable a visual interface for selecting a specific color. Some options are provided through properties on this control.


Example. To begin, we will add the ColorDialog instance to the form and then use it in some C# code. Most of the work you do with the ColorDialog will require the ShowDialog method and also the Color property.

FontDialog Box:

FontDialog presents a font selection dialog box. It allows the user to select a font from the list of installed fonts. With the FontDialog control, we quickly add the ability for users to select their favorite fonts.


SaveFileDialog in C#::


A SaveFileDialog control is used to save a file using Windows Save File Dialog. A typical Save File Dialog looks like Figure 1 where you can see Windows Explorer like features to navigate through folders and save a file in a folder. 
Creating a SaveFileDialog:
We can create a SaveFileDialog control using a Forms designer at design-time or using the SaveFileDialog class in code at run-time (also known as dynamically). Unlike other Windows Forms controls, a SaveFileDialog does not have and not need visual properties like others.




OpenFileDialog in C#:


An OpenFileDialog control is used to browse and select a file on a computer. This article demonstrates how to use a windows Forms open file dialog in C#.


Creating a OpenFileDialog
We can create an OpenFileDialog control using a Forms designer at design-time or using the OpenFileDialog class in code at run-time (also known as dynamically). Unlike other Windows Forms controls, an OpenFileDialog does not have and not need visual properties like others. The only purpose of OpenFileDialog to display available colors, create custom colors and select a color from these colors. Once a color is selected, we need that color in our code so we can apply it on other controls.



C#(Code)...........

Example

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

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

        private void button1_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            richTextBox1.SelectionColor = colorDialog1.Color;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            fontDialog1.ShowDialog();
            richTextBox1.SelectionFont = fontDialog1.Font;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
            richTextBox1.SaveFile(saveFileDialog1.FileName);

        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {

                richTextBox1.LoadFile(openFileDialog1.FileName);
           
            }
        }

     
    }
}



Comments