Docsity

Understanding MDI Parent and Child Properties and Events in MDI Windows, Slides of Programming for Engineers

Partial preview of the text

Download Understanding MDI Parent and Child Properties and Events in MDI Windows and more Slides Programming for Engineers in PDF only on Docsity!

Graphical User Interface-IV

Multiple-Document-Interface (MDI) Windows

  • Users can edit multiple documents at once
  • Usually more complex then single-document-interface

applications

  • Application window called parent, others child
  • Parent and child menus can be merged
    • Based on MergeOrder property
  • Child windows can be arranged in parent window:
    • Tiled windows: completely fill parent, no overlap
      • Either horizontal or vertical
    • Cascaded windows: overlap, same size, display title bar
    • ArrangeIcons: arranges icons for minimized windows

Multiple-Document-Interface (MDI) Windows

Single Document Interface (SDI) Multiple Document Interface (MDI)

Multiple-Document-Interface (MDI) Windows

MDI Form events and properties

Description / Delegate and Event Arguments

Common MDI Child Properties IsMdiChild (^) Indicates whether the Form is an MDI child. If true, Form is an

MDI child (read-only property). MdiParent (^) Specifies the MDI parent Form of the child.

Common MDI Parent Properties ActiveMdiChild (^) Returns the Form that is the currently active MDI child (returns null reference if no children are active). IsMdiContainer (^) Indicates whether a Form can be an MDI. If true, the Form can

be an MDI parent. Default is false. MdiChildren (^) Returns the MDI children as an array of Forms.

Common Method LayoutMdi (^) Determines the display of child forms on an MDI parent. Takes as a parameter an MdiLayout enumeration with possible values ArrangeIcons, Cascade, TileHorizontal and TileVertical. Figure 13.43 depicts the effects of these values. Common Event (Delegate EventHandler , event arguments EventArgs ) MdiChildActivate (^) Generated when an MDI child is closed or activated.

MDI parent and MDI child events and properties.

Multiple-Document-Interface (MDI) Windows

Separator bar and

child windows

9 or more child windows

enables the More

Windows... option

Child windows list

Multiple-Document-Interface (MDI) Windows

ArrangeIcons Cascade

1 // Fig. 13.44: Child.h 2 // Child window of MDI parent. 3 4 #pragma once 5 6 using namespace System; 7 using namespace System::ComponentModel; 8 using namespace System::Collections; 9 using namespace System::Windows::Forms; 10 using namespace System::Data; 11 using namespace System::Drawing; 12 using namespace System::IO; 13 14 namespace UsingMDI 15 { 16 ///

17 /// Summary for Form 18 /// 19 /// WARNING: If you change the name of this class, you will need to 20 /// change the ’Resource File Name’ property for the managed 21 /// resource compiler tool associated with all .resx files 22 /// this class depends on. Otherwise, the designers will not 23 /// be able to interact properly with localized resources 24 /// associated with this form. 25 ///

26 public __gc class Child : public System::Windows::Forms::Form 27 { 28 public: 29 Child( String *title, String *fileName ) 30 { 31 this->pictureBox = new PictureBox(); 32 Text = title; // set title text 33 34 InitializeComponent(); 35 36 // set image to display in pictureBox 37 pictureBox->Image = Image::FromFile( String::Concat( 38 Directory::GetCurrentDirectory(), fileName ) ); 39 } 40 41 protected: 42 void Dispose(Boolean disposing) 43 { 44 if (disposing && components) 45 { 46 components->Dispose(); 47 } 48 __super::Dispose(disposing); 49 } 50 private: System::Windows::Forms::PictureBox * pictureBox;

1 // Fig. 13.45: Form1.h 2 // Demonstrating use of MDI parent and child windows. 3 4 #pragma once 5 6 #include "Child.h" 7 8 namespace UsingMDI 9 { 10 using namespace System; 11 using namespace System::ComponentModel; 12 using namespace System::Collections; 13 using namespace System::Windows::Forms; 14 using namespace System::Data; 15 using namespace System::Drawing; 16 17 ///

18 /// Summary for Form 19 /// 20 /// WARNING: If you change the name of this class, you will need to 21 /// change the ’Resource File Name’ property for the managed 22 /// resource compiler tool associated with all .resx files 23 /// this class depends on. Otherwise, the designers will not 24 /// be able to interact properly with localized resources 25 /// associated with this form.

26 ///

27 public __gc class Form1 : public System::Windows::Forms::Form 28 { 29 public: 30 Form1(void) 31 { 32 InitializeComponent(); 33 } 34 35 protected: 36 void Dispose(Boolean disposing) 37 { 38 if (disposing && components) 39 { 40 components->Dispose(); 41 } 42 __super::Dispose(disposing); 43 } 44 private: System::Windows::Forms::MainMenu * mainMenu1; 45 private: System::Windows::Forms::MenuItem * fileMenuItem; 46 private: System::Windows::Forms::MenuItem * newMenuItem; 47 private: System::Windows::Forms::MenuItem * child1MenuItem; 48 private: System::Windows::Forms::MenuItem * child2MenuItem; 49 private: System::Windows::Forms::MenuItem * child3MenuItem; 50 private: System::Windows::Forms::MenuItem * exitMenuItem;

76 private: System::Void child2MenuItem_Click( 77 System::Object * sender, System::EventArgs * e) 78 { 79 // create new child 80 Child *formChild = new Child( S"Child 2", 81 S"\images\pythonhtp1.jpg" ); 82 formChild->MdiParent = this; // set parent 83 formChild->Show(); // display child 84 } // end method child2MenuItem_Click 85 86 // create Child 3 when menu clicked 87 private: System::Void child3MenuItem_Click( 88 System::Object * sender, System::EventArgs * e) 89 { 90 // create new child 91 Child *formChild = new Child( S"Child 3", 92 S"\images\vbnethtp2.jpg" ); 93 formChild->MdiParent = this; // set parent 94 formChild->Show(); // display child 95 } // end method child3MenuItem_Click 96 97 // exit application 98 private: System::Void exitMenuItem_Click( 99 System::Object * sender, System::EventArgs * e) 100 {

101 Application::Exit(); 102 } // end method exitMenuItem_Click 103 104 // set cascade layout 105 private: System::Void cascadeMenuItem_Click( 106 System::Object * sender, System::EventArgs * e) 107 { 108 this->LayoutMdi( MdiLayout::Cascade ); 109 } // end method cascadeMenuItem_Click 110 111 // set TileHorizontal layout 112 private: System::Void tileHorizontalMenuItem_Click( 113 System::Object * sender, System::EventArgs * e) 114 { 115 this->LayoutMdi( MdiLayout::TileHorizontal ); 116 } // end method tileHorizontalMenuItem_Click 117 118 // set TileVertical layout 119 private: System::Void tileVerticalMenuItem_Click( 120 System::Object * sender, System::EventArgs * e) 121 { 122 this->LayoutMdi( MdiLayout::TileVertical ); 123 } // end method tileVerticalMenuItem_Click 124 }; 125 }

User-Defined Controls

  • Custom controls that inherit from other classes
    • Ex: can change appearance of a label