Sams Teach Yourself Visual C# 2005 in 24 Hours, Complete Starter Kit
At some point, you might have changed your Windows theme, or perhaps you changed the image or color of your desktop. What you might 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, choose Properties from the shortcut menu to display the Display Properties dialog box, and then click the Appearance tab (see Figure 18.1). To change the color for a specific item, you click the Advanced button, select the color attribute to change, and then choose a new color (if you're running a version of Windows other than Windows XP, your dialog box might be slightly different). Figure 18.1. The Display Properties dialog box enables you to 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 application, it should also match its appearance to your selection. If you had to write code to manage this behavior, you'd have to write a lot of code, and you'd be justified in avoiding the whole mess. However, making an application adjust its appearance to match the user's system color selections is actually trivial, so there's no reason not to do it. For the most part, it's automatic with controls that you add to a form. 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 18.2). If you wanted to ensure that the color of a button matches the user's system color, for example, you would assign the System Color Control to the BackColor property of the Button control. Table 18.3 lists the most common system colors you can use. For a complete list, consult the online Help. Figure 18.2. System colors are assigned using the System palette tab.
When a user changes a system color using the Display Properties dialog box, Visual 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. Fortunately, when you create new forms and when you add controls to forms, Visual C# automatically assigns the proper system color to the appropriate properties, so you don't usually have to muck with them. 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 enables you to draw custom interface elements that match the user's system colors, for example. Be aware, however, that if you do draw with system colors, Visual 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. In addition, if you apply system colors to properties that aren't usually assigned system colors, you run the risk of displaying odd color combinations, such as black on black, depending on the user's color settings. By the Way Users don't just change their system colors for aesthetic purposes. I work with a programmer who is color-blind. He's modified his system colors so that he can see things better on the screen. If you don't allow your applications to adjust to the color preferences of the user, you might make using your program unnecessarily difficult, or even impossible, for someone with color-blindness or visual acuity issues. |
Категории