Sams Teach Yourself C# in 24 Hours
- Table of Contents
- Copyright
- About the Authors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- Audience and Organization
- Conventions Used in This Book
- Onward and Upward!
- Part I. The Visual Studio Environment
- Hour 1. A C# Programming Tour
- Hour 2. Navigating C#
- Hour 3. Understanding Objects and Collections
- Hour 4. Understanding Events
- Part II. Building a User Interface
- Hour 5. Building FormsPart I
- Hour 6. Building FormsPart II
- Hour 7. Working with the Traditional Controls
- Hour 8. Advanced Controls
- Hour 9. Adding Menus and Toolbars to Forms
- Hour 10. Drawing and Printing
- Part III. Making Things HappenProgramming!
- Hour 11. Creating and Calling Methods
- Hour 12. Using Constants, Data Types, Variables, and Arrays
- Hour 13. Performing Arithmetic, String Manipulation, and Date/Time Adjustments
- Hour 14. Making Decisions in C# Code
- Hour 15. Looping for Efficiency
- Hour 16. Debugging Your Code
- Hour 17. Designing Objects Using Classes
- Hour 18. Interacting with Users
- Part IV. Working with Data
- Hour 19. Performing File Operations
- Hour 20. Controlling Other Applications Using Automation
- Hour 21. Working with a Database
- Part V. Deploying Solutions and Beyond
- Hour 22. Deploying a Solution
- Hour 23. Introduction to Web Development
- Hour 24. The 10,000-Foot View
- Appendix A. Answers to Quizzes/Exercises
Using System Colors
At some point, you may have changed your Windows theme, or perhaps you changed the image or color of your desktop. What you may not be aware of is that Windows enables you to customize the colors of almost all Windows interface elements. The colors that Windows allows you to change are called system colors. To change your system colors, right-click the desktop and choose Properties from the shortcut menu to display the Display Properties dialog box, and then click the Appearance tab (see Figure 10.1). To change the color for a specific item, you can select the item from the Item drop-down list, or you can click the element in the top half of the tab.
Figure 10.1 The Display Properties dialog box lets you select the colors of most Windows interface elements.
When you change a system color using the Display Properties dialog box, all loaded applications should change their appearance to match your selection. In addition, when you start any new applications, they should also match their appearance to your selection. If you had to write code to manage this behavior, you would have to write a lot of code, and you would be justified in avoiding the whole thing. However, making an application adjust its appearance to match the user's system color selections is actually quite trivial; therefore, there's no reason not to do it.
To designate that an interface color should stay in sync with a user's system colors, you assign a system color to a color property of the item in question (see Figure 10.2). Table 10.3 lists the system colors you can use. For example, if you wanted to ensure that the color of a button matches the user's corresponding system color, you would assign the system color named Control to the BackColor property of the Button control.
Figure 10.2 System colors are assigned using the System palette tab.
Fortunately, when you create new forms and when you add controls to forms, C# automatically assigns the proper system color to the appropriate properties. Another good thing is that when a user changes a system color using the Display Properties dialog box, C# automatically updates the appearance of objects that use system colors; you don't have to write a single line of code to do this.
Be aware that you aren't limited to assigning system colors to their logically associated properties. You can assign system colors to any color property you want, and you can also use system colors when drawing. This allows you, for example, to draw custom interface elements that match the user's system colors. Be aware, however, that if you do draw with system colors, C# won't update the colors automatically when the user changes system colors; you would have to redraw the elements with the new system color.
Table 10.3. Properties of the SystemColors Class
| Enumeration | Description |
| ActiveBorder | The color of the filled area of an active window border. |
| ActiveCaption | The color of the background of an active caption bar (title bar). |
| ActiveCaptionText | The color of the text of the active caption bar (title bar). |
| AppWorkspace | The color of the application workspace. The application workspace is the area in a multiple-document view that is not being occupied by child windows. |
| Control | The color of the background of push buttons and other 3D elements. |
| ControlDark | The color of shadows on a 3D element. |
| ControlDarkDark | The color of darkest shadows on a 3D element. |
| ControlLight | The color of highlights on a 3D element. |
| ControlLightLight | The color of lightest highlights on a 3D element. |
| ControlText | The color of the text on buttons and other 3D elements. |
| Desktop | The color of the Windows desktop. |
| GrayText | The color of the text on a user-interface element when it's unavailable. |
| Highlight | The color of the background of highlighted text. This includes selected menu items as well as selected text. |
| HighlightText | The color of the foreground of highlighted text. This includes selected menu items as well as selected text. |
| HotTrack | The color used to represent hot tracking. |
| InactiveBorder | The color of an inactive window border. |
| InactiveCaption | The color of the background of an inactive caption bar. |
| InactiveCaptionText | The color of the text of an inactive caption bar. |
| Info | The color of the background of the ToolTip. |
| InfoText | The color of the text of the ToolTip. |
| Menu | The color of the menu background. |
| MenuText | The color of the menu text. |
| ScrollBar | The color of the scrollbar background. |
| Window | The color of the background in the client area of a window. |
| WindowFrame | The color of the frame around a window. |
| WindowText | The color of the text in the client area of a window. |
Working with Rectangles | Next Section

Account Sign In
View your cart