Lecture 7 Dialog Controls MDI Parent/Child Interaction.

Slides:



Advertisements
Similar presentations
A window application ---to know Dialogs (Week 7) ~csdywang/ta.htm.
Advertisements

Copyright © 2012 Pearson Education, Inc. Chapter 11 MORE WINDOWS CONTROLS & STANDARD DIALOG BOXES.
Dialog Boxes and Menus. Menus Menu Bar Contains menus which drop down to display list of menu items Each item has a name and text property Each item has.
C# - Files and Streams Outline Files and Streams Classes File and Directory Creating a Sequential-Access File Reading Data from a Sequential-Access.
Chapter 11 Data Files Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
File Access, Dialog Boxes, Error Handling, and Menus Chapter 5.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Dialog Boxes. Slide 2 The OpenFileDialog and SaveFileDialog Controls All dialog boxes derive from the CommonDialog class and share similar features The.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
1 Prototyping for HCI Spring 2004 (Week 7) Jorge A. Toro.
MDI windows Single-document-interface (SDI)
CVEV 118/698 Visual Basic Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
A Guide to Oracle9i1 Creating an Integrated Database Application Chapter 8.
Multiple Document Interface (MDI) application
DT265-2 Object Oriented Software Development 2 Lecture 3 : Windows Programming Lecturer Pat Browne
Printer & Dialog boxes Engr. Faisal ur Rehman CE-105T Spring 2007.
CIS162AD - C# Methods, Menus, and Dialog Boxes 05_methods_menus.ppt.
Microsoft Office 2003 Illustrated Introductory with Programs, Files, and Folders Working.
6 Copyright © 2004, Oracle. All rights reserved. Working with Data Blocks and Frames.
Dr Dat Tran - Week 4 Lecture Notes 1 MenuStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
Using Excel Session 2 Dr. Gary Briers Texas A&M University.
File Handling. Data Files Programs that can only get data from the user interface are limited. –data must be entered each time. –only small amounts of.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
MDI vs. SDI MDI – Multiple Document Interface SDI – Single Document Interface In an SDI application, each form acts independently of the others. A MDI.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Lecture 8 Building an MDI Application. Introduction The MDI (Multiple Document Interface) provides a way to display multiple (child) windows forms inside.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
Dr Dat Tran - Week 4 Lecture Notes 1 ToolStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
11-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
BIL528 – Bilgisayar Programlama II Introduction 1.
Lecture Set 12 Sequential Files and Structures Part A – Dialog Boxes, Filters, Directories.
CIS Intro to JAVA Lecture Notes Set June-05 GUI Programming – Assignment 5 Notes.
1 Chapter Nine Using GUI Objects and the Visual Studio IDE.
Lecture 6: Advanced GUI Controls. Up to now we have used simple controls such as buttons and textboxes. Now we will review some interactive (e.g. dialog)
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Common Dialogs.  What is a Common Dialog/Why use them?  Open Dialog  Save File As Dialog  Color Dialog  Font Dialog  Print Dialog.
Copyright © 2012 Pearson Education, Inc. Chapter 5 Loops, File, and Random Numbers.
The Professional Touch Programming Right from the Start with Visual Basic.NET 1/e 10.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Lecture 14: File I/O Common Dialogs Toolbox Widgets.
Chapter 5 Menus, Sub Procedures and Sub Functions Programming In Visual Basic.NET.
1 Printing a Document. 2 Objectives You will be able to print a real multipage document.
Understanding Desktop Applications Lesson 5. Understanding Windows Forms Applications Windows Forms applications are smart client applications consisting.
McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 11 Data Files.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
Building a Simple Text Editor. Create a text editor with the following features: (1) Uses a MenuStrip with File, and Edit tabs (2) The user can create.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
1 Displaying Dialog Boxes Kashef Mughal. 2 Midterm Stats Here we go  Average was  Low was 116  High was 184  Mid Quarter Grade - check any.
Module 3: Creating Windows-based Applications. Overview Creating the Main Menu Creating and Using Common Dialog Boxes Creating and Using Custom Dialog.
CIS 338: Dialog Boxes Dr. Ralph D. Westfall April, 2011.
Working with Data Blocks and Frames
Using GUI Objects and the Visual Studio IDE
File Input/Output (I/O)
Picture Viewer.
How to Add Images Using an 'openFile' Dialog
Multi-form applications and dialogs
MDI Picture Viewer Application
Creating a Windows Forms User Interface
Gathering User Input Event Handling Create Dynamic controls
Multi-Form Applications Things You Need to Know
Module 8: Creating Windows-based Applications
Lecture 5 Menu Strip Demo with Dialog Controls.
Presentation transcript:

Lecture 7 Dialog Controls MDI Parent/Child Interaction

Multiple Document Interface Text Editor

private void fontToolStripMenuItem_Click(object sender, EventArgs e) { if (this.ActiveMdiChild != null) { FontDialog fontdlg = new FontDialog(); fontdlg.Font = this.ActiveMdiChild.Controls[0].Font; fontdlg.ShowDialog(); this.ActiveMdiChild.Controls[0].Font = fontdlg.Font; } 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]

private void fontColorToolStripMenuItem_Click(object sender, EventArgs e) { if (this.ActiveMdiChild != null) { ColorDialog cdlg = new ColorDialog(); cdlg.Color = this.ActiveMdiChild.Controls[0].ForeColor; cdlg.ShowDialog(); this.ActiveMdiChild.Controls[0].ForeColor = cdlg.Color; } 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. ColorDialog

private void backgroundColorToolStripMenuItem_Click(object sender, EventArgs e) { if (this.ActiveMdiChild != null) { ColorDialog cdlg = new ColorDialog(); cdlg.Color = this.ActiveMdiChild.Controls[0].BackColor; cdlg.ShowDialog(); this.ActiveMdiChild.Controls[0].BackColor = cdlg.Color; } ColorDialog

private void makeNewMdiChild() { MDIEditor.frmChild child = new MDIEditor.frmChild(this); child.Show(); this.ActiveMdiChild.Text = "New-File-" + Convert.ToString(newindex); newindex += 1; } private void newToolStripMenuItem_Click(object sender, EventArgs e) { makeNewMdiChild(); } private void openFile() { OpenFileDialog openFileDlg = new OpenFileDialog(); openFileDlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDlg.FilterIndex = 1; if (openFileDlg.ShowDialog() == DialogResult.OK) { makeNewMdiChild(); this.ActiveMdiChild.Text = openFileDlg.FileName; StreamReader r = new StreamReader(openFileDlg.FileName); this.ActiveMdiChild.Controls[0].Text = r.ReadToEnd(); r.Close(); } private void openToolStripMenuItem_Click(object sender, EventArgs e) { openFile(); } 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-#. 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.

private void cascadeToolStripMenuItem_Click(object sender, EventArgs e) { this.LayoutMdi(MdiLayout.Cascade); } private void horizontalToolStripMenuItem_Click(object sender, EventArgs e) { this.LayoutMdi(MdiLayout.TileHorizontal); } private void verticalToolStripMenuItem_Click(object sender, EventArgs e) { this.LayoutMdi(MdiLayout.TileVertical); } Arrange - Cascade, Horizontal, Vertical when there are more than three child forms, the Arrange operations do not produce results implied by their names. CascadeTileHorizontalTileVertical >3 forms 3 forms

private void saveFileAs() { SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDlg.FilterIndex = 1; if (saveFileDlg.ShowDialog() == DialogResult.OK) { StreamWriter w = new StreamWriter(saveFileDlg.OpenFile()); w.Write(this.ActiveMdiChild.Controls[0].Text); w.Close(); this.ActiveMdiChild.Text = saveFileDlg.FileName; } private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { if (this.ActiveMdiChild != null) saveFileAs(); else MessageBox.Show("Nothing to Save"); } Save As - SaveFileDialog

private void saveFile() { SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDlg.FilterIndex = 1; saveFileDlg.FileName = this.ActiveMdiChild.Text; StreamWriter w = new StreamWriter(saveFileDlg.OpenFile()); w.Write(this.ActiveMdiChild.Controls[0].Text); w.Close(); } private void saveToolStripMenuItem_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"); } private void saveFileAs() { SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDlg.FilterIndex = 1; if (saveFileDlg.ShowDialog() == DialogResult.OK) { StreamWriter w = new StreamWriter(saveFileDlg.OpenFile()); w.Write(this.ActiveMdiChild.Controls[0].Text); w.Close(); this.ActiveMdiChild.Text = saveFileDlg.FileName; } Save - SaveFileDialog

Copy Style Paste Style public Color fontColor = Color.Black; public Color bkgColor = Color.White; public Font font; : private void 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; } private void 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; } class-level variables default Colors no default font specified One of the most difficult tasks of applications development is the prediction and effective management of atypical User Behavior

private void closeToolStripMenuItem_Click(object sender, EventArgs e) { if(this.ActiveMdiChild != null) this.ActiveMdiChild.Dispose(); } Closing a Form private void closeToolStripMenuItem_Click(object sender, EventArgs e) { if(this.ActiveMdiChild != null) this.ActiveMdiChild.Close(); } 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.