Dialog Controls

Post on 06-Feb-2016

219 views 0 download

description

DIALOG CONTROLS.ppt

transcript

DIALOG CONTROLS•These controls are used to perform opening a file saving afile,applying font, color attributes,perform page settings and printer settings etc……•Different Types of Dialog Controls•OpenFileDialog Control•SaveFileDialog Control•Font Dialog Control•Color Dialog Control•PageSetupDialog Control•Print Dialog Control

OpenFileDialog Control

• This control is used to display open file dialog box to the user so that user can select any file to Open.• This control is available in using

System.Windows.Forms.OpenFiledialogBox

Properties of Open File DialogS.No PROPERTIES DESCRIPTION

1. DefaultExt This is the DefaultExt for opening Files. it is used wild card technique for filtering file names .if the value of DefaultExt is *.doc here files with extension doc will open Open File Dialog.

2. FileName This property is used to store Name of the file i.e. selected by the user.

3. Filter This property is used to filter the files like text files, word files ,excel files all files etc…

4. Dialog Result It shows whet ether user has selected the OK or cancel button to the close Dialog box

SaveFileDialog Control

• This control is used to display Save file dialog box to the user so that user can save any filename.

• This control is available in using System.Windows.Forms.SaveFileDialogBox

Properties of Save File DialogS.No PROPERTIES DESCRIPTION

1. FileName This property is used to store Name of the file i.e. selected by the user.

2. Filter This property is used to filter the files like text files, word files ,excel files all files etc…

Font Dialog BoxControl• This control is used to display font dialog box to

the user so that user can select required font • Properties:• Font: this property is used to store the Font

attributes selected by the user within the dialog control

• Max Size:which is used to set the max font size.• Min Size:which is used to set the min font size.• Show Affects: user can access the Show affects

option within the Font dialog control

Color Dialog Control

• This control is used to display Color Dialog Box to the user so that user can select required Color.

• Properties:• Color:this property stores the color value

whenever any color selected by the user• FullOpen :when set true color dialog will open

in full mode other wise it will open in partial mode.

PAGE SETUP DIALOG CONTROLS• This control is used to display Pagesetup

Dialog Box to the user so that user can perform page settings to the required user.

• Properties :this property is used to set the print document for the user which would like to perform page settings.

PRINT DIALOG CONTROLS

• This control is used to display pagesetup dialog box to the user so that user can perform page settings to the document.

• Properties:• Document: this property is used to set the

print document name for which user will select printer settings to the printout.

Method with all Dialog Controls

• Show Dialog():this method is used to display the dialog control to the user.

Working with Menus • Menu control will display on the top of the

application• Main menu is represented in .net by System.

Windows .Forms.MainMenu Class• Drag and drop menu control in the toolbox

Code for Private SaveFile Method #region Private SaveFile Method private bool SaveFile() { string fname; DialogResult res = saveFileDialog1.ShowDialog(); fname = saveFileDialog1.FileName; StreamWriter fsave = new StreamWriter(fname); fsave.WriteLine(textBox1.Text); fsave.Flush(); fsave.Close(); this.Text = fname; // saveChek = false; textBox1.Clear(); return true;

} #endregion

#region mnunew_Click private void mnunew_Click(object sender, EventArgs e) { textBox1.Text = "";

} #endregion

Code for mnuopen_Click #region mnuopen_Click private void mnuopen_Click(object sender, EventArgs e) { // textBox1.Text = ""; // openFileDialog1.ShowDialog(); //MessageBox.Show(openFileDialog1.FileName); // StreamReader sr = new StreamReader(openFileDialog1.FileName); // string s = sr.ReadToEnd(); // textBox1.Text = s;

openFileDialog1.InitialDirectory = Environment.SpecialFolder.Programs.ToString(); openFileDialog1.Filter = "textfiles *.txt|*.txt"; if (openFileDialog1.ShowDialog() == DialogResult.OK)

using (StreamReader t = new StreamReader(openFileDialog1.FileName)) { textBox1.Text = t.ReadToEnd(); }

} #endregion

Private SaveFile Method#region Private SaveFile Method private bool SaveFile() { string fname; DialogResult res = saveFileDialog1.ShowDialog(); fname = saveFileDialog1.FileName; StreamWriter fsave = new StreamWriter(fname); fsave.WriteLine(textBox1.Text); fsave.Flush(); fsave.Close(); this.Text = fname; // saveChek = false; textBox1.Clear(); return true;

} #endregion

Code for mnusave_Click

#region mnusave_Click private void mnusave_Click(object sender,

EventArgs e) { SaveFile();

}

Code for mnuquit_Click

#region mnuquit_Click private void mnuquit_Click(object sender,

EventArgs e) { Application.Exit(); }

mnupagesetup_Click

#region mnupagesetup_Click private void mnupagesetup_Click(object

sender, EventArgs e) { PageSettings pg =new PageSettings(); pageSetupDialog1.PageSettings= pg; pageSetupDialog1.ShowDialog(); }

mnuprintdialog_Click

#region mnuprintdialog_Click private void mnuprintdialog_Click(object

sender, EventArgs e) { printDialog1.ShowDialog(); }

#endregion

Code for mnucut_Click

#region mnucut_Click private void mnucut_Click(object sender,

EventArgs e) { textBox1.Cut(); }

Code for mnucopy_Click

#region mnucopy_Click private void mnucopy_Click(object sender,

EventArgs e) { textBox1.Copy(); } #endregion

Code for mnupaste_Click

#region mnupaste_Click private void mnupaste_Click(object

sender, EventArgs e) { textBox1.Paste(); } #endregion

Code for mnuselectall_Click

• #region mnuselectall_Click private void mnuselectall_Click(object

sender, EventArgs e) { textBox1.SelectAll(); }

Code for mnuundo_Click

#region mnuundo_Click private void mnuundo_Click(object sender,

EventArgs e) { textBox1.Undo(); }

mnuaboutus_Click

Take a new form about.cs#region mnuaboutus_Click private void mnuaboutus_Click(object sender,

EventArgs e) { About abt = new About(); abt.Show(); this.Hide(); } #endregion

mnuclose_Click

#region mnuclose_Click private void mnuclose_Click(object sender,

EventArgs e) { this.Close(); } #endregion

code for mnufont_Click

#region mnufont_Click private void mnufont_Click(object sender,

EventArgs e) { fontDialog1.ShowDialog(); textBox1.Font = fontDialog1.Font; } #endregion

mnucolordialog_Click #region mnucolordialog_Click private void mnucolordialog_Click(object sender,

EventArgs e) { colorDialog1.ShowDialog(); //textBox1.ForeColor = colorDialog1.Color;

}

Drag and Drop Tool Strip

Form1_Closingprivate void Form1_Closing(object sender,

System.ComponentModel.CancelEventArgs e) {if (textBox1.Text != strMyOriginalText) {if(MessageBox.Show("Do you want to save

changes to your text?", "My Application", MessageBoxButtons.YesNo) == DialogResult.Yes)

{e.Cancel = true; } } }

MDI APPLICATION

• The applications that we allow the user to work with more than one files or documents at once are known as MDI applications

• Ex :MsEcel,Msword,MsPowerPoint etc…