Lecture 7
Download
1 / 11

Lecture 7 Dialog Controls MDI Parent/Child Interaction - PowerPoint PPT Presentation


  • 129 Views
  • Uploaded on

Lecture 7 Dialog Controls MDI Parent/Child Interaction. Multiple Document Interface Text Editor. FontDialog. An instance of the FontDialog class has fields and methods for displaying and selecting font types, sizes and styles.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Lecture 7 Dialog Controls MDI Parent/Child Interaction' - chesna


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Lecture 7

Dialog Controls

MDI Parent/Child Interaction



FontDialog

An instance of the FontDialog class has fields and methods for displaying and selecting font types, sizes and styles.

In an MDI application we can direct actions onto the ActiveMdiChild from the MdiParent

The widgets on a form are called Controls and can be accessed by their index value.

For example the richtextbox of New-File-0 is this.ActiveMdiChild.Controls[0]

privatevoidfontToolStripMenuItem_Click(object sender, EventArgs e)

{

if (this.ActiveMdiChild != null)

{

FontDialog fontdlg = newFontDialog();

fontdlg.Font = this.ActiveMdiChild.Controls[0].Font;

fontdlg.ShowDialog();

this.ActiveMdiChild.Controls[0].Font = fontdlg.Font;

}

}


ColorDialog

The ColorDialog can be used to select a standard color or to create a custom color that can be applied to any object that has a Color property.

privatevoid fontColorToolStripMenuItem_Click(object sender, EventArgs e)

{

if (this.ActiveMdiChild != null)

{

ColorDialog cdlg = newColorDialog();

cdlg.Color = this.ActiveMdiChild.Controls[0].ForeColor;

cdlg.ShowDialog();

this.ActiveMdiChild.Controls[0].ForeColor = cdlg.Color;

}

}


ColorDialog

privatevoid backgroundColorToolStripMenuItem_Click(object sender, EventArgs e)

{

if (this.ActiveMdiChild != null)

{

ColorDialog cdlg = newColorDialog();

cdlg.Color = this.ActiveMdiChild.Controls[0].BackColor;

cdlg.ShowDialog();

this.ActiveMdiChild.Controls[0].BackColor = cdlg.Color;

}

}


makeNewMdiChild( )

A new frmChild Form is created each time this method is called. A class-level variable, newindex is used to create a unique name for each new Form New-File-#.

privatevoid makeNewMdiChild()

{

MDIEditor.frmChild child = new MDIEditor.frmChild(this);

child.Show();

this.ActiveMdiChild.Text = "New-File-" + Convert.ToString(newindex);

newindex += 1;

}

privatevoid newToolStripMenuItem_Click(object sender, EventArgs e)

{

makeNewMdiChild();

}

privatevoid openFile()

{

OpenFileDialog openFileDlg = newOpenFileDialog();

openFileDlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

openFileDlg.FilterIndex = 1;

if (openFileDlg.ShowDialog() == DialogResult.OK)

{

makeNewMdiChild();

this.ActiveMdiChild.Text = openFileDlg.FileName;

StreamReader r = newStreamReader(openFileDlg.FileName);

this.ActiveMdiChild.Controls[0].Text = r.ReadToEnd();

r.Close();

}

}

privatevoid openToolStripMenuItem_Click(object sender, EventArgs e)

{

openFile();

}

creates a new instance of frmChild and

gives it a unique name.

called when File-> New is clicked...

also called when File->Open is clicked and filename returned from openFileDlg

returns DialogResult.OK.

in this case the name of the frmChild is changed to openFileDlg.FileName.


Arrange - Cascade, Horizontal, Vertical

Cascade

TileHorizontal

TileVertical

>3 forms 3 forms

privatevoid cascadeToolStripMenuItem_Click(object sender, EventArgs e)

{

this.LayoutMdi(MdiLayout.Cascade);

}

privatevoid horizontalToolStripMenuItem_Click(object sender, EventArgs e)

{

this.LayoutMdi(MdiLayout.TileHorizontal);

}

privatevoid verticalToolStripMenuItem_Click(object sender, EventArgs e)

{

this.LayoutMdi(MdiLayout.TileVertical);

}

when there are more than three child forms, the Arrange operations do not produce results implied by their names.


Save As - SaveFileDialog

privatevoid saveFileAs()

{

SaveFileDialog saveFileDlg = newSaveFileDialog();

saveFileDlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

saveFileDlg.FilterIndex = 1;

if (saveFileDlg.ShowDialog() == DialogResult.OK)

{

StreamWriter w = newStreamWriter(saveFileDlg.OpenFile());

w.Write(this.ActiveMdiChild.Controls[0].Text);

w.Close();

this.ActiveMdiChild.Text = saveFileDlg.FileName;

}

}

privatevoid saveAsToolStripMenuItem_Click(object sender, EventArgs e)

{

if (this.ActiveMdiChild != null)

saveFileAs();

else

MessageBox.Show("Nothing to Save");

}


Save - SaveFileDialog

privatevoid saveFile()

{

SaveFileDialog saveFileDlg = newSaveFileDialog();

saveFileDlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

saveFileDlg.FilterIndex = 1;

saveFileDlg.FileName = this.ActiveMdiChild.Text;

StreamWriter w = newStreamWriter(saveFileDlg.OpenFile());

w.Write(this.ActiveMdiChild.Controls[0].Text);

w.Close();

}

private voidsaveToolStripMenuItem_Click(object sender, EventArgs e)

{

if (this.ActiveMdiChild != null)

{

if (this.ActiveMdiChild.Text.Substring(0, 9) == "New-File-")

saveFileAs();

else

saveFile();

}

else

MessageBox.Show("Nothing to Save");

}

privatevoid saveFileAs()

{

SaveFileDialog saveFileDlg = newSaveFileDialog();

saveFileDlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

saveFileDlg.FilterIndex = 1;

if (saveFileDlg.ShowDialog() == DialogResult.OK)

{

StreamWriter w = newStreamWriter(saveFileDlg.OpenFile());

w.Write(this.ActiveMdiChild.Controls[0].Text);

w.Close();

this.ActiveMdiChild.Text = saveFileDlg.FileName;

}

}


class-level variables

Paste Style

publicColor fontColor = Color.Black;

publicColor bkgColor = Color.White;

publicFontfont;

:

privatevoid copyStyleToolStripMenuItem_Click(object sender, EventArgs e)

{

if (this.ActiveMdiChild != null)

{

fontColor = this.ActiveMdiChild.Controls[0].ForeColor;

bkgColor = this.ActiveMdiChild.Controls[0].BackColor;

font = this.ActiveMdiChild.Controls[0].Font;

}

}

privatevoid pasteStyleToolStripMenuItem_Click(object sender, EventArgs e)

{

if (this.ActiveMdiChild != null)

{

this.ActiveMdiChild.Controls[0].ForeColor = fontColor;

this.ActiveMdiChild.Controls[0].BackColor = bkgColor;

if (font != null)

this.ActiveMdiChild.Controls[0].Font = font;

}

}

default Colors

no default font specified

Copy Style

One of the most difficult tasks of applications development is the prediction and effective management of atypical User Behavior


Closing a Form

We commonly refer to the action of removing a child form as Closing the Form. Actually what we are doing is disposing the form:

Dispose( ) releases the object and prevents further use. Its memory resources are available for garbage collection, but are not necessarily returned immediately to the heap.

Close( ) hides the object from view while leaving its properties, fields, methods, etc available.

privatevoid closeToolStripMenuItem_Click(object sender, EventArgs e)

{

if(this.ActiveMdiChild != null)

this.ActiveMdiChild.Dispose();

}

privatevoid closeToolStripMenuItem_Click(object sender, EventArgs e)

{

if(this.ActiveMdiChild != null)

this.ActiveMdiChild.Close();

}


ad