- Back to Home »
- Windows Applications »
- Dialogs
Posted by :
Sudhir Chekuri
Thursday, 18 February 2016
Dialogs will allow the user give their inputs.
ColorDialog
Allows the user to select a color from the system colors.
FolderBrowserDialog
Allows the user to select a folder his system.
FontDialog
Allows the user to select the font style available in the system.
OpenFileDialog
Allows the user to select a file from the system.
SaveFileDialog
Allows the user to select a location where he can save a file.
Example code to use all the dialogs
Drag and drop five button to the form and also all the five dialog controls to the form which are displayed on the bottom panel.
Change the text of the buttons to Color, Folder, Font, Open File and Save File and Names to BtnColor, BtnFolder, BtnFont, BtnOpenFile, BtnSaveFile.
Double click on each button to create the events and write the below code in them
ColorDialog
Allows the user to select a color from the system colors.
FolderBrowserDialog
Allows the user to select a folder his system.
FontDialog
Allows the user to select the font style available in the system.
OpenFileDialog
Allows the user to select a file from the system.
SaveFileDialog
Allows the user to select a location where he can save a file.
Example code to use all the dialogs
Drag and drop five button to the form and also all the five dialog controls to the form which are displayed on the bottom panel.
Change the text of the buttons to Color, Folder, Font, Open File and Save File and Names to BtnColor, BtnFolder, BtnFont, BtnOpenFile, BtnSaveFile.
Double click on each button to create the events and write the below code in them
private void BtnColor_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
BtnColor.BackColor = colorDialog1.Color;
}
private void BtnFolder_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
BtnFolder.Text = folderBrowserDialog1.SelectedPath;
}
private void BtnFont_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
BtnFont.Font = fontDialog1.Font;
}
private void BtnOpenFile_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
BtnOpenFile.Text = openFileDialog1.FileName;
}
private void BtnSaveFile_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
}