Application = code + markup Reading Notes 2 (Chapter 2 Basic painter)

Source: Internet
Author: User
Color

You can use the new method or its static method color. fromrgb (R, G, B) or color. fromargb (A, R, G, B) to obtain

Color is a struct.

There are also some colors classes in the system. Window. Media namespace, including 141 static read-only attributes (whose names begin alphabetically with aliceblue and antiquewhite and conclude with yellow and yellowgreen ).

Inheritance relationship of the brush

This chapter describes solidcolorbrush and gradientbrush (abstract) (and its subclass lineargradientbrush radialgradientbrush). The following is the class inheritance relationship diagram:

Object dispatcherobject (abstract) dependencyobject freezable (abstract) animatable (abstract) brush (abstract) gradientbrush (abstract) lineargradientbrush radialgradientbrush solidcolorbrush tilebrush (abstract) drawingbrush imagebrush visualbrush
Brush is widely used in control background and other color-related attributes.

In WPF, color is a simple structure, while brush is the main character of color.

How to construct a solidcolorbrush?
    1. The constructor of solidcolorbrush receives a color parameter, which can be obtained through the method first introduced in this chapter.
    2. Solidcolorbrush has a property color that can be used to change the color of a solidcolorbrush by assigning values.
    3. Brushes has 141 predefined monochrome colors corresponding to colors, but cannot be assigned directly:
// Get an invalid operation exception that States // "cannot set a property on object '# ff000000 'because it is in a read-only state. "solidcolorbrush brush = brushes. black; // you can do this: solidcolorbrush brush = brushes. black. clone ();

Note: The third reason is that the static variable black of brushes has been frozen.

The solidcolorbrush objects returned from the brushes class are in a frozen state, which means they can no longer be altered. like the changed event, freezing is implemented in the freezable class, from which brush inherits. if the canfreeze property of a freezable object is true, it's possible to call the freeze method to render the object frozen and unchangeable. the isfrozen Property indicates this state by becoming true. freezing objects can improve performance because they no longer need to be monitored for changes. A frozen freezable object can also be shared with SS threads, while an unfrozen freezable object cannot. although you cannot unfreeze a frozen object, you can make an unfrozen copy of it.
System Image painter and its advantages

Systemcolors is similar to brushes and colors. For example, it can obtain the color and paint brush as follows:

Systemcolors. windowcolorbrush and systemcolors. windowcolor can also be modified as follows:

 
Brush = new systemcolorbrush (systemcolors. windowcolor );
Gradientbrush

Including lineargradientbrush and radialgradientbrush

Lineargradientbrush linear gradient Paint Brush Two constructor types are introduced.
    1. New lineargradientbrush (colors. Red, colors. Blue, new point (0, 0), new point (1, 1 ));
    2. New lineargradientbrush (clr1, clr2, angle );
Attributes such as spreadmethod, gradientstops, startpoint, and Endpoint
    1. By setting these attributes, you can change the appearance of gradientbrush.
Radialgradientbrush radial gradient Paint Brush

Similar to lineargradientbrush, only the direction of the color gradient is radial

The author provides several interesting examples to illustrate the features of these brushes.

This chapter introduces the attributes of the control class borderbrush, borderthickness, and foreground.

introduces the next chapter: The concept of content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.