wpf solidcolorbrush和brush的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20839719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:20:13  来源:igfitidea点击:

Difference between solidcolorbrush and brush

c#.netwpf

提问by daniyalahmad

What is the the differnce between solidcolorbrush and brush, In WPF (C#).

在 WPF (C#) 中,solidcolorbrush 和 Brush 之间有什么区别。

SolidColorBrush br = new SolidColorBrush(Colors.Red);

and

Brush br = Brushes.Red;

回答by Rohit Vats

To answer your question No difference.

回答你的问题没有区别

Brushes.Redreturns SolidColorBrushonly. Its definition is like:

Brushes.RedSolidColorBrush只返回。它的定义是这样的:

public static SolidColorBrush Red { get; }

You can assume its default template which Microsoft provides you for basic colors.

您可以假设 Microsoft 为您提供的基本颜色的默认模板。



Use SolidColorBrush constructor in case you want to provide your own custom A,R,G,Bvalues for color.

如果您想为颜色提供自己的自定义 A、R、G、B值,请使用 SolidColorBrush 构造函数。

This will get you actual Redcolor:

这将为您提供实际Red颜色:

enter image description here

在此处输入图片说明

SolidColorBrush anotherBrush = 
                     new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));

This will get you Red color with Gcomponent set to 100 byteand Bcomponent set to 50 byte.

这将使您获得红色,G组件设置为100 byte并且B组件设置为50 byte

enter image description here

在此处输入图片说明

SolidColorBrush anotherBrush = 
                     new SolidColorBrush(Color.FromArgb(255, 255, 100, 50));

回答by Patrick Hofman

None.

没有任何。

MSDN says:

MSDN 说:

public static SolidColorBrush Red { get; }

So in fact this is a static SolidColorBrush. With your first line of code you create a similar object.

所以实际上这是一个静态的 SolidColorBrush。使用第一行代码创建一个类似的对象。

回答by gomi42

Brush is the base class and holds any type of brush no matter how it was created. SolidColorBrush constructs a brush having a solid Color, LinearGradientBrush is another way to constract a brush and there are by far more. And WPF offers a huge set of predefined brushes in the Brushes class. They are of type SolidColorBrush just in order to say: a single, solid color.

Brush 是基类,可以容纳任何类型的画笔,无论它是如何创建的。SolidColorBrush 构造一个具有纯色的画笔,LinearGradientBrush 是另一种构造画笔的方法,而且还有更多。WPF 在 Brushes 类中提供了大量预定义的画笔。它们属于 SolidColorBrush 类型只是为了表示:单一的纯色。