1 / 54

Chapter 12: Using Controls

Learn how to examine the automatically generated code in the Visual Studio IDE and set the font of controls in a Windows Forms project.

sharons
Download Presentation

Chapter 12: Using Controls

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. Chapter 12: Using Controls

  2. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the nameFormWithALabelAndAButton ALabelhas been dragged ontoForm1and its properties updated AButtonhas been dragged ontoForm1and its properties updated Microsoft Visual C# 2012, Fifth Edition

  3. Examining the IDE’s Automatically Generated Code (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  4. Examining the IDE’s Automatically Generated Code (cont’d.) • Within the Form1.Designer.cs file in Visual Studio, two lines of code are generated as follows: private System.Windows.Forms.Label label1; private System.Windows.Forms.Button okButton; • These lines appear under a gray box that contains Windows Form Designer generated code • Expand the code generated by clicking the + in the method node or double-clicking the gray box Microsoft Visual C# 2012, Fifth Edition

  5. Examining the IDE’s Automatically Generated Code (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  6. Setting a Control’s Font • Use the Fontclass to change the appearance of printed text on your Forms • Change the appearance of printed text using code • Create your own instance of the Font class • The class includes a number of overloaded constructors • Example: System.Drawing.Font bigFont = new System.Drawing.Font("Courier New", 16.5f); this.label1.Font = bigFont; this.okButton.Font = bigFont; Microsoft Visual C# 2012, Fifth Edition

  7. Setting a Control’s Font (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  8. Setting a Control’s Font (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  9. Setting a Control’s Font (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  10. Usinga LinkLabel • LinkLabel • Similar to a Label • Provides the additional capability to link the user to other sources • Such as Web pages or files • Default event • The method whose shell is automatically created when you double-click the Control • The method you are most likely to alter with Control • The event that users most likely expect to generate Microsoft Visual C# 2012, Fifth Edition

  11. Using a LinkLabel (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  12. Using a LinkLabel (cont’d.) Microsoft Visual C# 2012, Fifth Edition • LinkLabel appears as underlined text • The text is blue by default • When you pass the mouse pointer over a LinkLabel, the pointer changes to a hand • When a user clicks a LinkLabel, it generates a click event • Executing a LinkClicked() method • The LinkVisited property can be set to true when you determine that a user has clicked a link

  13. Using a LinkLabel (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  14. Using a LinkLabel (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  15. Using a LinkLabel (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  16. Adding Color to a Form • Color class • Contains a wide variety of predefined Colors that you can use with your Controls • You can change a Form’s color using its BackColor and ForeColor properties Microsoft Visual C# 2012, Fifth Edition

  17. Using CheckBox and RadioButton Objects • CheckBox objects • GUI widgets the user can click to select or deselect an option • RadioButtons • Similar to CheckBoxes • Only one RadioButton in a group can be selected at a time Microsoft Visual C# 2012, Fifth Edition

  18. Using CheckBox and RadioButton Objects (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  19. Using CheckBox and RadioButton Objects (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  20. Using CheckBox and RadioButton Objects (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  21. Using CheckBox and RadioButton Objects (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  22. Using CheckBox and RadioButton Objects (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  23. Adding a PictureBox to a Form • PictureBox • A Control in which you can display graphics from a bitmap, icon, JPEG, GIF, or other image file type Microsoft Visual C# 2012, Fifth Edition

  24. Microsoft Visual C# 2012, Fifth Edition

  25. Adding a PictureBox to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition

  26. Adding a PictureBox to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition

  27. Adding ListBox, CheckedListBox, and ComboBoxControls to a Form • ListBox, ComboBox, and CheckedListBox objects • List-type widgets that descend from ListControl • ListBoxControl • Displays a list of items the user can select by clicking • Allows the user to make a single selection or multiple selections by setting the SelectionMode property • SelectedItem property • Contains the value of the item a user has selected Microsoft Visual C# 2012, Fifth Edition

  28. Adding ListBox, CheckedListBox, and ComboBoxControls to a Form (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  29. Adding ListBox, CheckedListBox, and ComboBoxControls to a Form (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  30. Adding ListBox, CheckedListBox, and ComboBoxControls to a Form (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  31. Adding ListBox, CheckedListBox, and ComboBoxControls to a Form (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  32. Adding ListBox, CheckedListBox, and ComboBoxControls to a Form (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  33. Adding ListBox, CheckedListBox, and ComboBoxControls to a Form (cont’d.) Microsoft Visual C# 2012, Fifth Edition • ComboBoxControl • Similar to a ListBox • Displays an additional editing field • Allows the user to select from the list or to enter new text • CheckedListBoxControl • Similar to a ListBox • Check boxes appear to the left of each desired item

  34. Adding ListBox, CheckedListBox, and ComboBoxControls to a Form (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  35. Adding MonthCalendar and DateTimePickerControls to a Form • MonthCalendar and DateTimePickerControls • Allow you to retrieve date and time information Microsoft Visual C# 2012, Fifth Edition

  36. Adding MonthCalendar and DateTimePickerControls to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition

  37. Adding MonthCalendar and DateTimePickerControls to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition

  38. Adding MonthCalendar and DateTimePickerControls to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition

  39. Adding MonthCalendar and DateTimePickerControls to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition

  40. Adding MonthCalendar and DateTimePickerControls to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition • DateTimePickerControl • Displays a month calendar when the down arrow is selected

  41. Adding MonthCalendar and DateTimePickerControls to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition

  42. Adding MonthCalendar and DateTimePickerControls to a Form(cont’d.) Microsoft Visual C# 2012, Fifth Edition

  43. Working with a Form’s Layout • Blue snap lines • Appear when you drag multiple Controls onto a Form • Help align new Controls with others already in place • Appear when you place a control closer to the edge of a container than is recommended • Can use the Location property in the Properties list to specify a location Microsoft Visual C# 2012, Fifth Edition

  44. Working with a Form’s Layout (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  45. Working with a Form’s Layout (cont’d.) • Dockproperty • Attaches a Control to the side of a container so that the Control stretches when the container’s size is adjusted Microsoft Visual C# 2012, Fifth Edition

  46. Working with a Form’s Layout (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  47. Working with a Form’s Layout (cont’d.) Microsoft Visual C# 2012, Fifth Edition

  48. Understanding GroupBoxes and Panels • GroupBoxorPanel • Groups related Controls on a Form • Can be docked inside a Form • GroupBoxes • Can display a caption • Do not have scroll bars • Panels • Cannot display a caption • Have scroll bars Microsoft Visual C# 2012, Fifth Edition

  49. Adding a MenuStrip to a Form • Menu strip • A horizontal list of general options that appears under the title bar of a Form or Window • You can add a MenuStripControl object to any Form you create • When you double-click an entry in the MenuStrip, a Click() method is generated Microsoft Visual C# 2012, Fifth Edition

  50. Adding a MenuStrip to a Form (cont’d.) Microsoft Visual C# 2012, Fifth Edition

More Related