Tải bản đầy đủ (.ppt) (39 trang)

Windows Controls pot

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (344.5 KB, 39 trang )

Week 3
Windows Controls
Contents

MenuStrip and ContextMenuStrip control (p.147)

TreeView (p.110)

Advanced topics (p.521)
Slide 2
Create MenuStrip at run-time

Add a menu to MenuStrip control at run-time

MenuStrip.Items.Add method

Example:
MenuStrip.Items.Add("File");
MenuStrip.Items.Add("View");

Add a menu item to other menu item at run-time

ToolStripMenuItem.DropDownItems.Add method

Example:
ToolStripItem mnuOpen;
mnuOpen = fileToolStripMenuItem.DropDownItems.Add("Open");
mnuOpen.Click += new EventHandler(mnuOpen_Click);
Slide 3
ContextMenuStrip control (p.173)


ContextMenuStrip similar to the MenuStrip control

The main difference between the ContextMenuStrip
and the MenuStrip

ContextMenuStrip control does not have a top-level
menu

Not visible at run time unless invoked by right-clicking
the control that it is associated with
Slide 4
ContextMenuStrip control (cont.)

Associating a ContextMenuStrip property with a
control

Using ContextMenuStrip property of a control or

Write in Mouse_Up event handler

ContextMenuStrip1.Show(Control, X, Y)

Demo:

Module 4 – Exercise 3 (modified)
Slide 5
TreeView control (p.110)

The TreeView control
allows you to display a

list of objects in a
hierarchical manner

Node

Root

Parent Node

Child Node

Level of nodes

TreeNode object
Slide 11
TreeView properties

Nodes: gets the collection of child nodes belong to
TreeView

FullRowSelect: True/False

HideSelection: True/False

ImageList

LabelEdit: True/False

ShowLines: True/False


SelectedNode: get or set the selected node
Slide 12
TreeNode properties

Text

ImageIndex

SelectedImageIndex

IsSelected

Level

Parent

Nodes: gets the collection of child nodes belong to a
TreeNode
Slide 16
TreeNode methods
Methods Description
Expand() Expands a node
Collapse() Collapses a node
ExpandAll() Expands all the children of a node
CollapseAll() Collapses all the children of a node
GetNodeCount() Return the number of child node
Slide 17
Methods, properties of TreeView,
TreeNode


Some important methods, properties of the TreeView,
TreeNode:

.Nodes.Add( string text )

.Nodes.Add( TreeNode node )

.Nodes.Remove( TreeNode node )

.Nodes.RemoveAt( int index )

.Nodes.Clear()

.Nodes.Count

.Nodes[int index]: returns a TreeNode object
Slide 18
Default event of TreeView

AfterSelect event: occurs when the selection has
been changed
private void treeview1_AfterSelect(…)
{
if (treeview1.SelectedNode != null)
{
// process selected node
}
}
Slide 19
Operations on TreeView control


Add node

Delete selected node

Display selected node

Visit nodes

Search and select node

Expanding and collapsing nodes

Level of TreeNode

Using Tag property of TreeNode
Slide 20
Add node

To add root node to TreeView:

TreeView1.Nodes.Add(…)

To add a node to the root node:

TreeView1.Nodes[0].Nodes.Add(…)

To add a node to the second child node of root node:

TreeView1.Nodes[0].Nodes[1].Nodes.Add(…)


Rule to add node:
1. Get the parent node
2. Add a node to that parent node
Slide 21
Add node (cont.)

Example 1: Add a node to selected node

Example 2: Create tree
TreeNode root;
root = treeView1.Nodes.Add("Công ty IBM");
root.Nodes.Add("Phòng tiếp thị");
root.Nodes[0].Nodes.Add("Lam Trường");
TreeNode parent = TreeView1.SelectedNode;
parent.Nodes.Add(TextBox1.Text);
Slide 22
Delete selected node
private void DeleteSelectedNode(TreeView tree)
{
if (tree.SelectedNode != null)
tree.Nodes.Remove(tree.SelectedNode);
}
Slide 23
Display selected node
private void treeview1_AfterSelect(…)
{
if (treeview1.SelectedNode != null)
{
TextBox1.Text = treeview1.SelectedNode.Text;

//
}
}
Slide 24
Visit direct children of the node

Visitting direct children of selected node, by:

You can visit direct children of any node
foreach (TreeNode node in tree.SelectedNode.Nodes)
{
// process node
}
Slide 25
Search and select node

Set HideSelection property is false

Loop all node using node visiting

Note EnsureVisible property for selected TreeNode
foreach (TreeNode node in SearchNode.Nodes)
{
if (match)
{
treeView1.SelectedNode = node;
}
}
Slide 26
Expanding and collapsing nodes


Expand and collapse methods of node

Use Expand or Collapse method of TreeView,
TreeNode

Expand all node

Using recursion

Treeview1.ExpandAll();

Example

Write program to expand - collapse all node in Module
5 exercise 1
Slide 27
Level of TreeNode

Use Level property to process the node you want
Slide 28
Using Tag property of TreeNode

Using Tag property to store information you want

Set Tag property for each TreeNode
Slide 29
Advanced topics in Windows Forms

MDI application (p.553)


The NotifyIcon component (p.123)

Drag-Drop (p.533)

Self-study

Using user assistance controls and components (p.573-
p.590)

Implementing Globalization and Localization for a
Windows Forms application (p.543)

Deploying applications with ClickOnce (p.669)

Creating setup projects for deployment (p.676)
Slide 32
MDI application (p.553)

Multiple Document Interface (MDI) Windows
Single Document Interface (SDI) Multiple Document Interface (MDI)
IsMdiContainer = False
IsMdiContainer = True
Slide 33
Redisplaying child windows
Find form
If existing
ActivateShow
If not existing
private void HienForm( Form f )

{
bool thay = false;
foreach (Form frm in this.MdiChildren)
{
if (frm.Name.ToUpper().Equals(f.Name.ToUpper()))
{
frm.Activate();
thay = true;
}
}
if (thay == false)
{
f.MdiParent = this;
f.Show();
}
}
Slide 34
private void menu_Click(…)
{
frmSV frm = new frmSV();
HienForm(frm);
}
The NotifyIcon component
(p.123)

The NotifyIcon component is a component that
represents an icon that appears in the system tray

usually used with applications that run in the
background


can provide information about the program execution
(Text property)

can be associated with a context menu
(ContextMenuStrip property)
Slide 35

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×