0% found this document useful (0 votes)
2 views35 pages

Lecture 8 VP

The document provides an overview of Tab Control and Multiple Document Interface (MDI) in software development, detailing their properties, events, and examples of usage. It explains how Tab Controls create tabbed windows for better information organization and how MDI allows multiple child windows within a single parent window. Additionally, it includes code examples demonstrating the implementation of these controls in a Windows Forms application.

Uploaded by

Ahmed Al-nasheri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views35 pages

Lecture 8 VP

The document provides an overview of Tab Control and Multiple Document Interface (MDI) in software development, detailing their properties, events, and examples of usage. It explains how Tab Controls create tabbed windows for better information organization and how MDI allows multiple child windows within a single parent window. Additionally, it includes code examples demonstrating the implementation of these controls in a Windows Forms application.

Uploaded by

Ahmed Al-nasheri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Dr.

Ahmed Alnasheri
Contents
Tab Control
Multiple Document Interface (MDI)
Visual Inheritance (Search about it) G
User-Defined Controls (Search about it ) B

2
TabControl
 Creates tabbed windows

 Specify more information in the same amount of space

 Contain TabPage objects

 Add controls to the TabPage objects

 Add the TabPages to the TabControl

 Only one TabPage is displayed at a time

 To view different TabPages click the appropriate tab


 Click event

 Generated when TabPage’s tab is clicked


3
Tab pages
Tab Controls

Fig. 7.1 Tabbed pages in Visual Studio .NET.


4
Tab Controls

TabPage TabControl

Controls in TabPage

Fig. 7.2 TabControl with TabPages example.

5
Tab Controls

Fig. 7.3 Adding TabPages to the TabControl.

6
Tab Control Properties
TabControl properties Description / Delegate and Event Arguments
and events
Common Properties
ImageList Specifies images to be displayed on a tab.
ItemSize Specifies tab size.
MultiLine Indicates whether multiple rows of tabs can be displayed.
SelectedIndex Indicates index of TabPage that is currently selected.

SelectedTab Indicates the TabPage that is currently selected.


TabCount Returns the number of tabs.
TabPages Gets the collection of TabPages within our
TabControl.
Common Event (Delegate EventHandler, event arguments
EventArgs)
SelectedIndexChanged Generated when SelectedIndex changes (i.e., another
TabPage is selected).
Fig. 7.4 TabControl properties and events.
7
Example 1 (Tab Properties)

8
Example 1 (using Tabs Form)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace tabPropertiesTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void tabTest_SelectedIndexChanged(object sender, EventArgs e)


{
label1.Text = tabTest.SelectedIndex.ToString() + " " + tabTest.SelectedTab.Name + tabTest.TabPages;

}
}
}
9
Example 2 (using Tabs Form)

10
Example
1 // Fig. 14.36: UsingTabsForm.cs
2 // Using TabControl to display various font settings.
3 using System;
4 using System.Drawing;
5 using System.Windows.Forms;
6
7 // Form uses Tabs and RadioButtons to display various font settings
8 public partial class UsingTabsForm : Form
9 {
10 // default constructor
11 public UsingTabsForm()
12 {
13 InitializeComponent();
14 } // end constructor
15
16 // event handler for Black RadioButton
17 private void blackRadioButton_CheckedChanged(
18 object sender, EventArgs e )
19 {
20 displayLabel.ForeColor = Color.Black; // change font color to black
21 } // end method blackRadioButton_CheckedChanged
22
23 // event handler for Red RadioButton
24 private void redRadioButton_CheckedChanged(
25 object sender, EventArgs e )
26 {
27 displayLabel.ForeColor = Color.Red; // change font color to red
28 } // end method redRadioButton_CheckedChanged 11
Example
29
30 // event handler for Green RadioButton
31 private void greenRadioButton_CheckedChanged(
32 object sender, EventArgs e )
33 {
34 displayLabel.ForeColor = Color.Green; // change font color to green
35 } // end method greenRadioButton_CheckedChanged
36
37 // event handler for 12 point RadioButton
38 private void size12RadioButton_CheckedChanged(
39 object sender, EventArgs e )
40 {
41 // change font size to 12
42 displayLabel.Font = new Font( displayLabel.Font.Name, 12 );
43 } // end method size12RadioButton_CheckedChanged
44
45 // event handler for 16 point RadioButton
46 private void size16RadioButton_CheckedChanged(
47 object sender, EventArgs e )
48 {
49 // change font size to 16
50 displayLabel.Font = new Font( displayLabel.Font.Name, 16 );
51 } // end method size16RadioButton_CheckedChanged
12
Example
52
53 // event handler for 20 point RadioButton
54 private void size20RadioButton_CheckedChanged(
55 object sender, EventArgs e )
56 {
57 // change font size to 20
58 displayLabel.Font = new Font( displayLabel.Font.Name, 20 );
59 } // end method size20RadioButton_CheckedChanged
60
61 // event handler for Hello! RadioButton
62 private void helloRadioButton_CheckedChanged(
63 object sender, EventArgs e )
64 {
65 displayLabel.Text = "Hello!"; // change text to Hello!
66 } // end method helloRadioButton_CheckedChanged
67
68 // event handler for Goodbye! RadioButton
69 private void goodbyeRadioButton_CheckedChanged(
70 object sender, EventArgs e )
71 {
72 displayLabel.Text = "Goodbye!"; // change text to Goodbye!
73 } // end method goodbyeRadioButton_CheckedChanged
74 } // end class UsingTabsForm
13
Software Engineering Observation
 A TabPage can act as a container for a single logical
group of RadioButtons, enforcing their mutual
exclusivity. To place multiple RadioButton groups inside
a single TabPage, you should group RadioButtons
within Panels or GroupBoxes contained within the
TabPage.

14
Multiple Document Interface (MDI)
 Multiple Document Interface (MDI)

 Parent window

 Main application window

 Only one in application

 Child window

 Each window inside the application

 Only one child can be active at a time

 Cannot also be a parent window

 As many child windows as you want 15


Multiple Document Interface (MDI)
MDI parent

MDI child

MDI child

Fig. 7.5 MDI parent and MDI child.

16
Multiple Document Interface (MDI)

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

Fig. 7.6 SDI and MDI forms.


17
Multiple Document Interface (MDI)
 Creating an MDI Form
 Create a new Form
 Set these

 Create a child Form (Right Click on the Application  Add  New Item)
 Add the child Form to the parent
 Set its MdiParent property to the parent Form

 Call the child Form’s Show method


Form2 frm2 = new Form2();
frm2.Show();
 To add a child Form to a parent, write: frm2.MdiParent = this;
 ChildFormClass childForm = New ChildFormClass();
 childForm.MdiParent = parentForm;
 childForm.Show();
18
MDI – Properties and Events
MDI Form events and Description / Delegate and Event Arguments
properties
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 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.35 depicts the effects of these values.
Common Event (Delegate EventHandler, event arguments
EventArgs)
MdiChildActivate Generated when an MDI child is closed or activated.
Fig. 7.7 MDI parent and MDI child events and properties.
19
Good Programming Practice

• When creating MDI applications, include a menu that


displays a list of the open child windows. This helps the
user select a child window quickly, rather than having to
search for it in the parent window.

20
Multiple Document Interface (MDI)

Parent’s icons: minimize, Maximized child’s icons: minimize,


maximize and close restore and close

Minimized child’s icons: restore, Parent’s title bar displays


maximize and close maximized child

Fig. 7.8 Minimized and maximized child windows.


21
Multiple Document Interface (MDI)

Separator bar and 9 or more child windows


child windows enables the More
Windows... option

Child windows list

Fig. 7.9 Using MenuItem property MdiList. 22


Multiple Document Interface (MDI)

ArrangeIcons Cascade

Fig. 7.10 LayoutMdi enumeration values (Part 1).

23
Multiple Document Interface (MDI)

TileHorizontal TileVertical

Fig. 7.11 LayoutMdi enumeration values (Part 2).

24
MDI Example 1

Fig. 7.12 MDI Form Application.

25
MDI Example 1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace mdiFormsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void mDIChildOneToolStripMenuItem_Click(object sender, EventArgs e)


{
Form2 frm2 = new Form2();
frm2.Show();
frm2.MdiParent = this;
}
26
MDI Example 1
private void mDIChildTwoToolStripMenuItem1_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
frm3.Show();
frm3.MdiParent = this;
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{
this.Close();
}

private void mDIChildThreeToolStripMenuItem_Click(object sender, EventArgs e)


{
Form4 frm4 = new Form4();
frm4.Show();
frm4.MdiParent = this;
}
}
}

27
MDI Example 2

28
MDI Example
1 // Fig. 14.43: UsingMDIForm.cs
2 // Demonstrating use of MDI parent and child windows.
3 using System;
4 using System.Windows.Forms;
5
6 // Form demonstrates the use of MDI parent and child windows
7 public partial class UsingMDIForm : Form
8 {
9 // default constructor
10 public UsingMDIForm()
11 {
12 InitializeComponent();
13 } // end constructor
14
15 // create Child 1 window when child1ToolStrip MenuItem is clicked
16 private void child1ToolStripMenuItem_Click(
17 object sender, EventArgs e )
18 {
19 // create new child
20 ChildForm formChild =
21 new ChildForm( "Child 1", @"\images\csharphtp1.jpg" );
22 formChild.MdiParent = this; // set parent
23 formChild.Show(); // display child
24 } // end method child1ToolStripMenuItem_Click
29
MDI Example
25
26 // create Child 2 window when child2ToolStripMenuItem is clicked
27 private void child2ToolStripMenuItem_Click(
28 object sender, EventArgs e )
29 {
30 // create new child
31 ChildForm formChild =
32 new ChildForm( "Child 2", @"\images\vbnethtp2.jpg" );
33 formChild.MdiParent = this; // set parent
34 formChild.Show(); // display child
35 } // end method child2ToolStripMenuItem_Click
36
37 // create Child 3 window when child3ToolStripMenuItem is clicked
38 private void child3ToolStripMenuItem_Click(
39 object sender, EventArgs e )
40 {
41 // create new child
42 Child formChild =
43 new Child( "Child 3", @"\images\pythonhtp1.jpg" );
44 formChild.MdiParent = this; // set parent
45 formChild.Show(); // display child
46 } // end method child3ToolStripMenuItem_Click
47
48 // exit application
49 private void exitToolStripMenuItem_Click( object sender, EventArgs e )
50 {
51 Application.Exit();
52 } // end method exitToolStripMenuItem_Click
30
MDI Example
53
54 // set Cascade layout
55 private void cascadeToolStripMenuItem_Click(
56 object sender, EventArgs e )
57 {
58 this.LayoutMdi( MdiLayout.Cascade );
59 } // end method cascadeToolStripMenuItem_Click
60
61 // set TileHorizontal layout
62 private void tileHorizontalToolStripMenuItem_Click(
63 object sender, EventArgs e )
64 {
65 this.LayoutMdi( MdiLayout.TileHorizontal );
66 } // end method tileHorizontalToolStripMenuItem
67
68 // set TileVertical layout
69 private void tileVerticalToolStripMenuItem_Click(
70 object sender, EventArgs e )
71 {
72 this.LayoutMdi( MdiLayout.TileVertical );
73 } // end method tileVerticalToolStripMenuItem_Click
74 } // end class UsingMDIForm

31
MDI Example
1 // Fig. 14.44: ChildForm.cs
2 // Child window of MDI parent.
3 using System;
4 using System.Drawing;
5 using System.Windows.Forms;
6 using System.IO;
7
8 public partial class ChildForm : Form
9 {
10 public ChildForm( string title, string fileName )
11 {
12 // Required for Windows Form Designer support
13 InitializeComponent();
14
15 Text = title; // set title text
16
17 // set image to display in pictureBox
18 picDisplay.Image = Image.FromFile(
19 Directory.GetCurrentDirectory() + fileName );
20 } // end constructor
21 } // end class ChildForm

32
Homework 7

33
Homework 7

34
The End
35

You might also like