比较画笔和颜色

发布于 2024-09-02 22:49:13 字数 114 浏览 3 评论 0原文

if (backBrush == SystemColors.ActiveCaption)

这失败了。说你不能比较画笔和颜色。

如何找到画笔的颜色?

if (backBrush == SystemColors.ActiveCaption)

This fails. Says you can't compare a brush and a color.

How do I find the color of the brush?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

獨角戲 2024-09-09 22:49:13

如果 backBrush 是 SolidColorBrush (根据您尝试执行的操作可能是)您可以使用:

if(((SolidColorBrush)backBrush).Color == SystemColors.ActiveCaption)

If backBrush is a SolidColorBrush (based on what you're trying to do it probably is) you can use:

if(((SolidColorBrush)backBrush).Color == SystemColors.ActiveCaption)
谁人与我共长歌 2024-09-09 22:49:13

如果画笔是 SolidBrush,您可以比较画笔的 Color 成员。像这样的东西。

SolidBrush solidBrush = brush as SolidBrush;
if (solidBrush != null && solidBrush.Color == SystemColors.ActiveCaption)
{
  // ....
}

以上适用于 WinForms,对于 WPF,您可以使用 SolidColorBrush 而不是 SolidBrush。

If the brush is a SolidBrush you can compare the Color member of the brush. Something like this.

SolidBrush solidBrush = brush as SolidBrush;
if (solidBrush != null && solidBrush.Color == SystemColors.ActiveCaption)
{
  // ....
}

The above is for WinForms, for WPF you would use SolidColorBrush rather than SolidBrush.

绿光 2024-09-09 22:49:13

画笔< /code>没有颜色。

您使用BrushColor进行填充/绘画等。

一些画笔可以 > 有颜色 (HatchBrush 有两个),因此您需要转换为画笔类型并比较颜色,然后:

((HatchBrush)backBrush).BackgroundColor == SystemColors.ActiveCaption

A Brush does not have a color.

You use a Brush with a Color for filling/painting etc.

Some brushes do have a color (HatchBrush has two), so you will need to cast to the type of brush and compare colors then:

((HatchBrush)backBrush).BackgroundColor == SystemColors.ActiveCaption
喜爱纠缠 2024-09-09 22:49:13

您是否尝试过 SystemBrushes 命名空间?

if (backBrush == SystemBrushes.ActiveCaption)
{...

Have you tried the SystemBrushes namespace?

if (backBrush == SystemBrushes.ActiveCaption)
{...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文