繁体   English   中英

如何引用某些Windows元素(滚动条,推入选项按钮等)使用的BG颜色?

[英]How to refer to BG-color, used by some Windows elements (scrollbar, pushed-in option button, etc.)?

有谁知道我如何在C#中引用系统背景颜色,用于滚动条或推入选项按钮或标签等元素(作为下图中“tabPage1”的背景)?
或者,如果不存在预定义的const,那么任何算法如何用这种颜色创建一个Brush? 谢谢!

tabPage1的背景表示所需的颜色

我的直觉首选SystemColors.ScrollBar结果相同.Control.ButtonFace (BG为“tabPage2”),这是真正为一个滚动条“面子”的色彩,不是我称之为“背景”。
SystemColors.ControlLightSystemColors.ControlLightLight不再接近..

放大时,控制的该区域看起来像一个棋盘用.Control.Window像素,因此,我认为在这种颜色被抖动的可能性提示; 也许这表明标准SystemColors枚举没有定义它的原因? 我如何将它应用于另一个控件?

放大视图暴露了抖动

PS:我正在尝试增强自定义TabControl(它支持可禁用的标签 - std控件中缺少的另一个好东西,但这是另一个已经解决的故事),所以当它的.Appearance设置为ButtonsFlatButtons ,它看起来很相似到原件(如上图所示)。 选定的选项卡由推入按钮指示,但其背景颜色设置为ControlButtonFace

在此输入图像描述

好吧,事实证明这比我想象的要简单得多 - 它只是用于填充BG-rect的Brush

protected override void OnDrawItem( DrawItemEventArgs e )
{
    base.OnDrawItem( e );

    int         i=  e.Index;
    TabPage     p=  this.TabPages[ i ];
    Rectangle   r=  GetTabRect( i );
    Brush       br= null;

    if(  this.Appearance != TabAppearance.Normal  &&  i == this.SelectedIndex  )
        br= new HatchBrush( HatchStyle.Percent50, SystemColors.Control, SystemColors.Window );
    else
        br= new SolidBrush( p.BackColor );

    try                     // fill the BG-rectangle
    {   e.Graphics.FillRectangle( br, r );      }
    finally
    {   br.Dispose( );  }   // make sure brush is disposed of

    ..  // the rest of the event-handler
}

唯一的技巧是无法应用using( Brush br= new .. ) {..}块,因为初始化与结果对象类型不同。 因此,一个有点丑陋的try-finally构造。 充当魅力!

对不起,我不太了解Forms,但是MFC有一个提供这种抖动位图( AfxGetDitheredBitmap )的功能,所以我假设你必须做类似的事情。

不幸的是,我找不到.Net等效函数,抱歉。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM