Lecture 8 VP
Lecture 8 VP
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
TabPage TabControl
Controls in TabPage
5
Tab Controls
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.
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();
}
}
}
}
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
Child window
MDI child
MDI child
16
Multiple Document Interface (MDI)
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
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
20
Multiple Document Interface (MDI)
ArrangeIcons Cascade
23
Multiple Document Interface (MDI)
TileHorizontal TileVertical
24
MDI Example 1
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();
}
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