1 / 52

Windows Software Development Lecture 4

Windows Software Development Lecture 4. MIS288 Instructor – Larry Langellier. Where Are We?. Last Lecture MDI programs CommonDialog control RichTextBox control Tonight – Introducing the Windows Common Controls Store images in the ImageList control

fifi
Download Presentation

Windows Software Development Lecture 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. Windows Software DevelopmentLecture 4 MIS288 Instructor – Larry Langellier

  2. Where Are We? • Last Lecture • MDI programs • CommonDialog control • RichTextBox control • Tonight – Introducing the Windows Common Controls • Store images in the ImageList control • Program the TreeView and ListView controls • Use the Toolbar and DTPicker • Also, the UpDown, ImageCombo, Slider, FlatScrollBar, ProgressBar, and StatusBar controls

  3. Windows Common Controls List • ImageList - repository for images • TreeView - displays information hierarchically • ListView - columnar list • Let’s look at the Windows Explorer

  4. ImageList Control • Repository for images used by other control instances • Key property contains the string key of an Image • ListImages collection stores reference to ListImage objects (the images stored in the control instance) • All images scaled to the same size • Stores bitmaps (.bmp), icons (.ico), graphical interchange format (.gif), jpeg (.jpg) and cursor files (.cur) • Purpose • Used by other control instances • Other control instances can share one instance of the ImageList control • ImageList control instance cannot be shared by different forms

  5. ImageList Property Page • Images Property Page manages the images • General Tab – set the image size • Color Tab – set the image background color Case sensitive string key to identify image Click to select Image

  6. Using the ImageList Control • Access an individual image via a numeric index or string key, like other collections • Example ilsLargeIcons.ListImages(“LargeOpenfold”) • Hands-On Example • Open Ch5_c.vbp • Adding an ImageList • ImageList Property Page

  7. TreeView control • Used to access and navigate hierarchically organized data • Each element in the tree is a Node object – in the Nodes collection • Nodes have relationships to other nodes • A node has one parent, and zero or more children • Properties determine the appearance of the TreeView • Drill-down interface similar to Windows Explorer

  8. TreeView control properties • CheckBoxes property causes check boxes to appear next to each node • ImageList property contains the name of an ImageList control instance on the form • LabelEdit property specifies manual or automatic editing • tvwAutomatic, tvwManual • LineStyle determines how nodes are connected • tvwTreeLines, tvwRootLines

  9. TreeView Nodes Collection • Nodes collection contains a reference to Node objects • Add method creates new nodes • Arguments control where a node is added • Remove method removes a node • Clear method removes all nodes • EnsureVisible forces the TreeView to scroll to make a node visible

  10. TreeView control events • Collapse/Expand occur when the user expands/collapses a node • NodeClick occurs when the user clicks the mouse while positioned over a node • Click occurs if the user clicks the mouse and is NOT over a node • NodeCheck occurs if the CheckBoxes property = True and if the user checks/unchecks a node • Hands-on Example • Add a TreeView control to frmETC • Properties: Name, Indentation, LabelEdit • Activate the Property Pages via “Custom” • Set the ImageList property to ilsSmallIcons

  11. Node Terminology • Think of the hierarchy as a family tree with only one parent • A single root node is at the top of the tree • A node can have zero or more children • All children with the same parent are known as siblings • A child node can only have one parent, parents can have several children • Child nodes can have children, which can in turn have their own children, etc.

  12. Node object properties • Child property contains a reference to the first child node • Children property is an Integer containing the number of children • Expanded property determines whether a node is expanded or collapsed • FirstSibling and LastSibling contain a reference to first and last nodes at the same level of the hierarchy • Node can display one of three icons defined by ExpandedImage, Image, and SelectedImage • Next and Previous properties contain a reference to the next and previous sibling • Parent property contains a reference to the parent node

  13. Adding a TreeView node • Syntax Object.Add ([relative][, relationship] _ [, key][, text][, image][, selectedimage] • Object: reference to the Nodes collection of a TreeView (tvwETC.Nodes) • relative: index or key of an existing node • relationship: constant to define relationship of new node to relative argument • key: unique string to identify node within collection • text: the visible text that appears to the right of the icon

  14. Adding a Root Node • Examples Set nodExample = tvwEtc.Nodes.Add() nodExample.Key = "Unique Value" nodExample.Text = "Visible Desc" nodExample.Image = "Openfold" Set nodExample = tvwEtc.Nodes.Add( _ , ,"Unique Value", "Visible Desc", _ "OpenFold")

  15. Adding a Child Node • Relative argument contains a reference to a node • Relationship argument contains a constant defining the placement of the new node • tvwFirst - tvwLast - tvwNext - tvwPrevious - tvwChild • Example Set nodExample = _ tvwEtc.Add(mnodRoot,tvwChild) Relative to mnodRoot Child of mnodRoot

  16. Continuing the Hands-On Example • Call InitTree in Form_Load to initialize all the values in the TreeView • Create a root-level node • InitTree • Add Office, Department and Employee children (based on info in a database) • InitTreeOffice • InitTreeDepartment • InitTreeEmployee

  17. Navigating the Tree • Navigation • Child property contains a reference to the first child • Children property contains a count of children Set pnodCurrent = pnod.Child For pintCurrent = 1 to pnod.Children Debug.Print pnodCurrent.Text Set pnodCurrent = pnodCurrent.Next Next • Traversing the entire tree ' Expand all the nodes in the tree. Dim pnodCurrent As Node For Each pnodCurrent in tvwEtc.Nodes pnodCurrent.Expanded = False Next

  18. Continuing the Hands-On Example • mnuFilePrint_Click • Traverse and Print the hierarchical contents of the TreeView • mnuDisplayCollapse_Click • Collapse all the top-level nodes of the TreeView • mnuDisplayExpand_Click • Expand all the top-level nodes of the TreeView

  19. Just Do It! • Work on Exercise 5.1 from the textbook (pages 327-328) • There is an executable demo (JDI1.exe) located in the Classroom Lecture Demos – feel free to run that to get a better idea of what you’re being asked to do • We will discuss the solution after you’ve worked on problem for a while • Call me over if you have questions – don’t sit there stumped for long

  20. ListView control • Commonly used with the TreeView control • Four views define the visual appearance • Icon • Small Icon • List • Report • ListItems collection and ListItem objects define the items in the list • Report View • ListSubItems collection and ListSubItem objects define the column contents • ColumnHeaders define the column headers

  21. ListView Properties • Arrange organizes icons in icon view and small icon view • lvwNone (default), lvwAutoLeft, lvwAutoRight • CheckBoxes causes check boxes to appear next to each item • GridLines pertains to report view and displays gridlines between rows and columns • Icons contains a reference to an ImageList control instance to display icons • SmallIcons also contains a reference to an ImageList • LabelEdit defines manual or automatic editing • Sorted indicates whether rows will be sorted • SortOrder indicates how rows will be sorted • lvwAscending (default), lvwDescending • SortKey determines which column will be sorted

  22. ListView control events • ColumnClick event occurs in report view when the user clicks a column header • ItemClick event occurs when user clicks an item

  23. The ListItem object • Each item in the list is represented by a ListItem object • Icon and SmallIcon properties define the icons • Text property contains the visible text • MultiSelect property allows user to select multiple items • Index and Key properties uniquely identify the ListItem in the ListItems collection • Adding a ListItem object • lvwDemo.Add(1,"Item”,”Item 1”,"IconsSmall","IconLarge") Index Icons String Key Text

  24. ListView Hierarchy ListView Control ListItems collection ListItem object ListItem object ListItem object

  25. Continuing the Hands-On Demo • Integrating the ListView and TreeView controls • Add a ListView control to the form • tvwETC_NodeClick • Add the employees to the ListView when appropriate • Write a Sub that clears the ListView • Write a Sub called InitializeList • Called from tvwETC_NodeClick • Adds items to the ListView for each employee in the selected department • Set the View property based on menu selection • Set the Arrange property based on menu selection

  26. The Report View • ColumnHeader objects identify each column • ListSubItem objects identify the information contained in columns 2 through n ListViewControl ColumnHeaders collection ColumnHeader object ColumnHeader object ColumnHeader object ListItems collection ListItem object ListSubItems collection ListSubItem object ListSubItem object

  27. ColumnHeader objects • ColumnHeader object • Each ColumnHeader corresponds to a SubItem. SubItemIndex contains the numeric index of the SubItem • Text property contains the text appearing in the column header identify each column • Add method adds a column header lvwEmployees.ColumnHeaders.Add 1, "Column1", _ "Description", 1500 Column Width String Key Text appears in column header

  28. Completing the Hands-On Example • Create Column Headers • Create ListSubItem objects • InitializeList • called from tvwETC_NodeClick • Enable column sorting • ColumnClick event

  29. Just Do It! • Work on Exercise 5.2 from the textbook (pages 329-330) • There is an executable demo (JDI2.exe) located in the Classroom Lecture Demos – feel free to run that to get a better idea of what you’re being asked to do • We will discuss the solution after you’ve worked on problem for a while • Call me over if you have questions – don’t sit there stumped for long

  30. The Next Hands-On Demo • International Carrier Systems • Flight Scheduling • Ch6_C.exe • Utilizes some fundamental concepts that you might need to review • User-defined Types • Arrays • Sequential File Processing • Control Arrays

  31. Lots of new controls… Toolbar FlatScrollBar ImageCombo DTPicker UpDown Slider StatusBar

  32. Toolbar Control • Associated with one or more ImageList controls • DisabledImageList used for disabled buttons • HotImageList used for button under mousepointer • ImageList used for normal buttons • Two categories of buttons • Ordinary buttons • Responds to ButtonClick event • Dropdown buttons (new to VB6) • Responds to ButtonMenuClick event when dropdown button is clicked • Responds to ButtonDropDown event when user clicks dropdown menu

  33. General Property Page Associate toolbar with ImageList controls Flat or raised toolbar Flat or raised buttons

  34. Buttons Property Page String key of button Type of button Used only when Style is set to tbrDropdown to create dropdown ButtonMenus String key or numeric index of Image in ImageList control

  35. Toolbar control buttons • Types of buttons • tbrDefault - similar to a command button • tbrCheck - appears pressed or unpressed • tbrButtonGroup - one button from a group can be pressed at a time • tbrSeparator - add a fixed amount of whitespace between two buttons • tbrPlaceholder - add variable whitespace between buttons. Whitespace used to insert other control instances • tbrDropdown- create a dropdown button

  36. Toolbar control objects • Object Representation • Each standard button is a Button object in the Buttons Collection • A Button object can contain a reference to a ButtonMenus collection (in the case of a dropdown button) • Dropdown buttons are members of the ButtonMenus collection ToolBar control Buttonscollection Buttonobject ButtonMenuscollection ButtonMenuobject

  37. Toolbar Code Examples • Referencing a button • Note Buttons is default collection so the following four statements are equivalent • Referencing a button menu. Using default collections, the following statements are equivalent tbrDemo.Buttons("ButtonKey").Visible = False tbrDemo.Buttons(1).Visible = False tbrDemo.("ButtonKey").Visible = False tbrDemo.(1).Visible = False tbrDemo.Buttons("ButtonKey"). _ ButtonMenus("Print").Visible = False tbrDemo.("ButtonKey"). _ ButtonMenus("Print").Visible = False

  38. Button events • Buttons respond to ButtonClick event Private Sub tbrDemo_ButtonClick _ (ByVal Button As MSComctlLib.Button) Select Case Button.Key Case "StringKey1" ' Task 1 Case "StringKey2" ' Task 2 . . . End Select End Sub Reference to Button String key of Button in Buttons collection String key of individual Button objects

  39. ButtonsMenu events • ButtonsMenu objects respond to ButtonMenuClick event Private Sub tbrDemo_ButtonMenuClick _ (ByVal ButtonMenu As MSComctlLib.ButtonMenu Select Case ButtonMenu.Key Case "stringKey1" ' Task 1 Case "StringKey2" ' Task 2 . . . End Select End Sub Reference to ButtonMenu String key of ButtonMenu in ButtonMenus collection String key of individual ButtonMenu objects

  40. DTPicker Control • General • Events • CloseUp event occurs when calendar portion is closed • Validate event occurs before control instance loses focus Formats date output Displays a calendar to input dates Automatic date validation

  41. DTPicker properties • Properties • CalendarBackColor, CalendarForeColor, CalendarTitleForeColor, and CalendarTitleBackColor control colors • DayOfWeek stores day of the week • Year, Month, Day, Hour, Minute, Second properties to read and write date and time parts • User selectable date range modifiable using MinDate and MaxDate • Can appear with a check box by setting CheckBox property • Format contains predefined formats • dtpShortDate - 06/26/1999 or 06/26/99 • Depends on system short date format • dtpLongDate - Saturday, June 26, 1999 • dtpTime - 12:00:00 AM

  42. UpDown Control • Conceptually a scroll bar bound to another control such as a text box • Second control is called a buddy • UpDown control and buddy controls are synchronized TextBox (txtDemo) UpDown control instance BuddyControl = txtDemo Textproperty BuddyProperty = Text

  43. UpDown Control (cont.) • Properties • BuddyControl property contains the name of the buddy control instance. Not all control types are supported – TextBoxes are common • BuddyProperty contains the name of the bound property (synchronized with buddy) • SyncBuddy synchronizes the two control instances if set to True • Max and Min properties define the range • Increment defines the rate of change • Value contains the current Integer value • Change event occurs when the value changes • DownClick and UpClick events occur when one of the arrows are clicked

  44. ImageCombo Control • General • Collection based implementation of the intrinsic combo box • Displays both text and image in an icon • Image and list must be built at run time • Properties • ComboItems collection contains the list of items • SelectedItem property contains a reference to current ComboItem object • Method • GetFirstVisible method returns a reference to first visible item • Event • DropDown event occurs just before drop-down list appears

  45. ComboItem objects • Properties • SelImage property contains string key or numeric index of image in ImageList control (when item is selected) • Boolean Selected property indicates whether a ComboItem is selected • Text property contains text appearing in the list • Image property contains image reference • ComboItem objects added at run time with the Add method • Example • First item - String key is USA. Text is "United States", image has a string key of 'flgUSA icDemo.ComboItems.Add 1, "USA", _ "United States", "flgUSA"

  46. Slider Control • General • Used to display a value within an Integer range • Functionally similar to a scroll bar • When the user drags the pointer, the Change event occurs and the Value property is reset • Properties • Orientation property displays the control vertically or horizontally • TextPosition determines the position of the ToolTip containing the current value • TickFrequency defines the number of tick marks • TickStyle defines where the tick marks appear • Value, Max, and Min are the same as an intrinsic scroll bar • Change event occurs when Value property changes

  47. FlatScrollBar control • Similar to intrinsic scroll bars • Appears flat instead of three dimensional • One control replaces vertical and horizontal scroll bars • Properties • Orientation property defines whether control instance appears vertically or horizontally • Min and Max define the range • LargeChange and SmallChange define the change increment • Change event occurs when Value changes

  48. ProgressBar Control • General • Used to display relative completion of an operation • Min and Max properties define the range • Value property defines relative completion • Scrolling property controls visual appearance • Orientation property makes control instance appear horizontal or vertical

  49. StatusBar Control • Typically appears at the bottom of the form • Display status of keyboard keys, date and time, and other program information • Displays one large panel or multiple panels depending on the value of Style property • Styles: • sbrText - Programmer defined text • sbrCaps - Caps lock key • sbrNum - NumLock key • sbrIns - Insert key • sbrScrl - ScrlLock key • sbrDate sbrTime - Date and time • The value of SimpleText appears when the Style displays 1 panel

  50. StatusBar Panels • Panel objects • Index and Key properties Identify a Panel object in the Panels collection • Style property defines the behavior of a panel • Text property defines the text appearing in a panel • Width and MinWidth determine the size of a panel • Example Make a panel invisible sbrDemo.Panels("CurrentRecord").Visible = False sbrDemo.Panels("Message").Text = "Enter a value" Store text in a panel

More Related