11.1 Drag-Drop P523Source control Target control +MouseDown -TXT1.DoDragDrop textBox1.Text, DragDropEffects.Copy AllowDrop=true +DragEnter if e.Data.GetDataPresent DataFormats.Text e.E
Trang 1Week 10
Chapter 11 Advanced Topics in
Windows Forms
Chapter 12 Enhancing Usability
Chapter 15: Crystal Report
Chapter 11 Advanced Topics
in Windows Forms
11.1 Drag-Drop (P523)
11.2 MDI (P543)
Trang 211.1 Drag-Drop (P523)
Windows users fall into two general
categories:
use the keyboard
use the mouse
Drag and drop: same as cutting and pasting
using keyboard
11.1 Drag-Drop (P523)
Sequence of events
Dragging is initiated (call DoDragDrop for the source )
The DoDragDrop method takes two parameters:
data
allowedEffects
A new DataObject object is automatically created
Raises the GiveFeedback event (display a custom
mouse pointer during the drag)
Control with AllowDrop =True can receive drop.
DragEnter raised (mouse pass).
Trang 311.1 Drag-Drop (P523)
Source control
Target control
+MouseDown
-TXT1.DoDragDrop
(textBox1.Text,
DragDropEffects.Copy )
AllowDrop=true
+DragEnter
if (e.Data.GetDataPresent (DataFormats.Text))
e.Effect = DragDropEffects.Copy;
+DragDrop
TXT2.Text = (string)e.Data.GetData ( DataFormats.Text);
Drag-Drop: demo: Textbox
Using Textbox
Step1: DragEnter event
Step2: DragDrop event
Step3: MouseDown event
Trang 4Drag-Drop: demo: PictureBox
AllowDrop
DragEnter
DragDrop
KeyState
11.1 DragDrop (P523)
-demo: treeview
Example: Drag-Drog in Treeview
treeview1.PointToClient(new Point(e.X, e.Y));
Clone node;
}
Trang 5form tree
Xform
Yform
Xcontrol
Ycontrol
Point_form(Xform,Yform)
Point_control(Xform,Yform)
C PointToClient(Point_form )
11.1 DragDrop (P523)
-demo: Listview
Make new collection
Array
ArrayList
List<generic>
Trang 611.2 MDI
parent form/child form model
Has a single parent form
The parent form organizes and
arranges all of the child documents that
are currently open.
11.2 MDI
What is an MDI Form?
Multiple-document interface (MDI)
applications allow you to display multiple
documents at the same time, with each
document displayed in its own window
Trang 711.2 MDI
How do I create an MDI Parent form ?
Creating an MDI Parent Form
IsMDIContainer=true
How do I create an MDI Child form ?
Creating MDI Child Forms
Set MdiParent to parent form
11.2 MDI
How do I change the Background color of an MDI Parent form?
private void MDIParent1_Load(object sender, EventArgs e)
foreach (Control c in this.Controls) {
MdiClient m = (MdiClient)c;
m.BackColor = Color.Red;
Trang 811.2 MDI
Identifying the Active Child Form
Form aForm;
aForm = this.ActiveMDIChild;
11.2 MDI
Arranging MDI Child Forms
this.LayoutMdi(System.Windows.Forms.Mdi
Layout.Cascade);
Trang 911.2 MDI
Window List Menu
MenuStrip component
Set the MdiWindowListItem property to the
menu item
11.2 MDI
How do I check if an MDI Child form already exists,
so that we don't show the same form twice?
foreach (Form f in this.MdiChildren)
if (f.Text == "Window 2")
this.ActivateMdiChild(f);
Trang 10Chapter 12 Enhancing
Usability
Lesson 2: Using User Assistance
Controls and Components
The ProgressBar Control
StatusStrip Control
ToolTip Component
ErrorProvider Component
HelpProvider Component
Chapter 12 Using User Assistance
Controls and Components
The ProgressBar Control
Visually indicate progress for a
time-consuming operation
Maximum, Minimum, Value, Step
progressBar1.Minimum = 0;
progressBar1.Maximum = 100;
progressBar1.Step = 1;
Trang 11Chapter 12 Using User Assistance
Controls and Components
StatusStrip Control
Display status information about the
application
ToolStripStatusLabel
Text
Chapter 12 Using User Assistance
Controls and Components
ToolTip Component
To set a tooltip in the Designer
To set a tooltip in code
toolTip1.SetToolTip(button1,
"This button activates the self-destruct
Trang 12Chapter 12 Using User Assistance
Controls and Components
ErrorProvider Component
provide feedback to the user when an error
condition results for a control in the form
Turn on
errorProvider1.SetError(TextBox1, "Value must
be numeric");
Turn off
errorProvider1.SetError(TextBox1, "");
Chapter 15: Report
Trang 13Chapter 15: Crystal Report
Crystal Report File
Crystal Report Viewer
Chapter 15: Crystal Report
1 Create Type Dataset
2 Create Crystal Report Template
Menu Project -> Add new item -> Crystal Report
->Using Report Wizard->choose
Typed-Dataset->…
Trang 14Chapter 15: Crystal Report
Typed Dataset
Dataset
Crystal Report.Rpt
Crystal Report Viewer
Class
Chapter 15: Crystal Report
//Create and Fill data into Dataset ds
CrystalReport1 c = new CrystalReport1();
c.SetDataSource(ds);
crystalReportViewer1.ReportSource = c;