cst238 week 4 questions / concerns? announcements – start thinking about project ideas – test#1...

20
CST238 Week 4 • Questions / Concerns? • Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 • Recap • Check-off Take Home Lab#3 • New topics – Dialogs (user-defined dialogs) – Timer control – DateTime object – Richtextbox – MDI (Multiple Document Interface) • Parent/child form relationship • Richtextbox – open, save, cut, copy, paste • In-Class Exercise #4 • Take Home Lab#4

Upload: claribel-merritt

Post on 31-Dec-2015

215 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

CST238 Week 4• Questions / Concerns?• Announcements

– Start thinking about project ideas– Test#1 next Monday, 4/28/14

• Recap• Check-off Take Home Lab#3• New topics

– Dialogs (user-defined dialogs)– Timer control– DateTime object– Richtextbox– MDI (Multiple Document Interface)

• Parent/child form relationship• Richtextbox – open, save, cut, copy, paste

• In-Class Exercise #4• Take Home Lab#4

Page 2: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Recap• Picturebox– Image property– Load method

• Layout controls– Table– Flow layout

• Menu• Toolbar• Status bar• Working with C# arrays

Page 3: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Dialog• Forms that:– Provide information to the user, or– Request information from the user

• Generally modal– Cannot switch forms until dialog is closed.

• Several dialogs included with Windows Forms– MessageBox, Color, OpenFile, SaveFile, Print, etc.

• You can create your own custom dialog

Page 4: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Working with Dialogs• Simple Dialogs– Just a function call• MessageBox.Show()

• Common/Custom Dialog– Create instance of dialog – Set properites– Show dialog using ShowDialog method• Returns a meber of the DialogResult enumeration

– Take action based on dialog result

Page 5: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Working with DialogOpenFieDialog openFile1 = new OpenFileDialog();

openFile1.Filter = “JPEG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|BMP Files (*.bmp)|*.bmp|All files (*.*)|*.*”;

if (openFile1.ShowDialog() == DialogResults.OK){ //Do something with OpenFile1.FileName //which is the filename selected by the user if (openFile1.ShowDialog() == DialogResult.OK) { pictureBox1.Load(openFile1.FileName); }

}

Page 6: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Working with Color DialogColorDialog colorDialog1 = new ColorDialog();

if (colorDialog1.ShowDialog() == DialogResult.OK) pictureBox1.BackColor = colorDialog1.Color; //selected color

Page 7: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Custom Dialog• Create form as you would any other• Set form properties to add dialog look, feel and behavior

– Set FormBorderStyle to FixedDialog• Disables resizing of dialog

– Set ControlBox property to false• Removes minimize, maximize and close buttons from title bar

– Set AcceptButton and CancelButton properties• AcceptButton - pressing Enter is the same as clicking the

button• CancelButton – pressing Escape is the same as clicking the

button

• Set dialog return value on button clicks– In event handler, or– Using the DialogResult property of the button

Page 8: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Timer Control• Add a timer control to the form• Set its interval – 1000 ms = 1 second• Set its Tick event handler to handle the timer

event at every interval

Page 9: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

DateTime• DateTime object in C# returns the current date and

time. • Custom Date and Time Format Strings:

http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

• Example:private DateTime timeOfDay;Private string timeString;private string hour;private string minute;timeOfDay = DateTime.Now;timeString = timeOfDay.ToString("hh:mm:ss");hour = timeOfDay.Hour.ToString("00");minute = timeOfDay.Minute.ToString("00");

Page 10: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Richtextbox• Supports– Cut– Copy– Paste– SelectAll– SaveFile(filename)– LoadFile(filename)– SelectionColor– SelectionFont

Page 11: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

MDI

Page 12: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Multiple Document Interface (MDI)

Page 13: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

MDI Apps• Main Form– Set IsMdiContainer to true– Use ActiveMdiChild to get reference to active child

form– Use MdiChildren to get collection of child forms– Use LayoutMdi to arrange child forms

• Child forms– Set MdiParent to main form on creation– Use MdiParent to get reference back to main form

Page 14: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

MDI• Windows menu– Arrange the windows in Cascade– Arrange the windows in Tile Horizontally– Arrange the windows in Tile Vertically

• Menustrip Control– Set MdiWindowList • This will show a list of active child windows

Page 15: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Access the Active Child form if (this.ActiveMdiChild != null){ //cast the ActiveMdiChild to the right form type ChildForm child=(ChildForm)this.ActiveMdiChild;

//do something with childform’s control child.documentTextbox.Undo(); }

documentTextbox is private. It needs to be internal. Change its modifier in the Properties window.

Page 16: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

private vs. internal• All controls on a form are default to private

modifier. – Only available to the containing form

• In order for the Main Form to access the Childform’s control, the control’s modifier would have to be changed.– internal means that they are in the same assembly

(.exe or .dll)

Page 17: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Modifiers

Page 18: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

In-Class Lab#4• Finish the MDI application by finishing the

Open, Save, Cut, Copy,Paste, Change Font and Change Color menu options.

• When open a new childForm window, set its title appropriately.

• Be sure to change the childForm window title to the saved/opened filename.

Page 19: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Take-Home Exercise #4• Build a Tix Clock

• This is a Tix Clock showing 15:43.

Page 20: CST238 Week 4 Questions / Concerns? Announcements – Start thinking about project ideas – Test#1 next Monday, 4/28/14 Recap Check-off Take Home Lab#3 New

Tix Clock• Use pictureboxes to simulate color LEDs.• Use random number to randomly color

squares.• Tix clocks are updated every 4 seconds.• Use DateTime to get the current time. Be sure

to grab 2 digits for hour and 2 digits for minute.