1 / 20

CST238 Week 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 topics Dialogs (user-defined dialogs) Timer control DateTime object Richtextbox MDI (Multiple Document Interface)

vince
Download Presentation

CST238 Week 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 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

  2. Recap • Picturebox • Image property • Load method • Layout controls • Table • Flow layout • Menu • Toolbar • Status bar • Working with C# arrays

  3. 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

  4. 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

  5. Working with Dialog OpenFieDialog 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); } }

  6. Working with Color Dialog ColorDialog colorDialog1 = new ColorDialog(); if (colorDialog1.ShowDialog() == DialogResult.OK) pictureBox1.BackColor = colorDialog1.Color; //selected color

  7. 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

  8. 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

  9. 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 DateTimetimeOfDay; 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");

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

  11. MDI

  12. Multiple Document Interface (MDI)

  13. 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

  14. 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

  15. 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(); } documentTextboxis private. It needs to be internal. Change its modifier in the Properties window.

  16. 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)

  17. Modifiers

  18. 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.

  19. Take-Home Exercise #4 • Build a Tix Clock • This is a Tix Clock showing 15:43.

  20. 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.

More Related