简体   繁体   English

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

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

Does anybody know how can I reference in C# a system background color, used on elements like scrollbar or pushed-in option button or tab (as the background for 'tabPage1' in the image below)? 有谁知道我如何在C#中引用系统背景颜色,用于滚动条或推入选项按钮或标签等元素(作为下图中“tabPage1”的背景)?
Or, if no predefined const exists, any algorithm how to create a Brush with this color? 或者,如果不存在预定义的const,那么任何算法如何用这种颜色创建一个Brush? Thank you! 谢谢!

tabPage1的背景表示所需的颜色

My intuitive first choice SystemColors.ScrollBar results in same as .Control or .ButtonFace (BG for 'tabPage2'), which is really a "face" color for the scrollbar, not what I'd call "background". 我的直觉首选SystemColors.ScrollBar结果相同.Control.ButtonFace (BG为“tabPage2”),这是真正为一个滚动条“面子”的色彩,不是我称之为“背景”。
SystemColors.ControlLight or SystemColors.ControlLightLight do not get any closer.. SystemColors.ControlLightSystemColors.ControlLightLight不再接近..

When zoomed in, that area of the control looks like a checker-board with .Control and .Window pixels, so to me that hints at a possibility of this color being dithered; 放大时,控制的该区域看起来像一个棋盘用.Control.Window像素,因此,我认为在这种颜色被抖动的可能性提示; maybe that indicates the reason why standard SystemColors enum does not define it? 也许这表明标准SystemColors枚举没有定义它的原因? How would I apply it to another control? 我如何将它应用于另一个控件?

放大视图暴露了抖动

PS: I'm trying to enhance a custom TabControl (which supports disableable tabs - another good thing missing from std controls, but that's another and already solved story), so that when its .Appearance is set to Buttons or FlatButtons , it looks similar to the original (illustrated above). PS:我正在尝试增强自定义TabControl(它支持可禁用的标签 - std控件中缺少的另一个好东西,但这是另一个已经解决的故事),所以当它的.Appearance设置为ButtonsFlatButtons ,它看起来很相似到原件(如上图所示)。 Selected tab is indicated by a pushed-in button, but its background color is set to Control or ButtonFace : 选定的选项卡由推入按钮指示,但其背景颜色设置为ControlButtonFace

在此输入图像描述

Ok, this turns out to be a lot simpler than I thought - it's just about the Brush , used to fill the BG-rect: 好吧,事实证明这比我想象的要简单得多 - 它只是用于填充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
}

The only trick is that a using( Brush br= new .. ) {..} block cannot be applied, as initialization differs with resulting object type. 唯一的技巧是无法应用using( Brush br= new .. ) {..}块,因为初始化与结果对象类型不同。 Hence, a somewhat ugly try-finally construct. 因此,一个有点丑陋的try-finally构造。 Works as a charm! 充当魅力!

I'm sorry I don't know Forms very well, but MFC has a function for providing such dithered bitmaps ( AfxGetDitheredBitmap ), so I assume you'll have to do something similar. 对不起,我不太了解Forms,但是MFC有一个提供这种抖动位图( AfxGetDitheredBitmap )的功能,所以我假设你必须做类似的事情。

Unfortunately I couldn't find a .Net equivalent function, sorry. 不幸的是,我找不到.Net等效函数,抱歉。

暂无
暂无

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

相关问题 .NET如何创建和执行其Windows,按钮等? - How does .NET create and execute its Windows, buttons, etc.? 如何在Silverlight中获取默认滚动条的子元素(例如,repeatbutton,thumb等)? - How to get child element of default scrollbar(e.g. repeatbutton, thumb, etc.) in silverlight? Xamarin MVVM:通过在 ViewModel 中完成的一些计算结果更新控件样式(字体大小、边框颜色等) - Xamarin MVVM: updating control styling (font size, border color etc.) by some calculation results done in ViewModel WPF FormattedText 在某些 fonts(ti、tf 等)中使用连字时会出现光栅化/剪切 - WPF FormattedText rasterises/cuts when ligatures used in some fonts (ti, tf, etc.) 如何在onDataBinding事件期间格式化单个DropDownlist项(颜色等) - How to format individual DropDownlist Items (color, etc.) during onDataBinding event 如何使用Java在Windows上创建虚拟磁盘(字母,共享等)? - How can I create a virtual disk (letter, share, etc.) on Windows using Java? 如何从注册表中获取Windows XP / 2003信息(版本,SP编号等)? - How to get Windows XP/2003 information(Edition, SP number, etc.) from the registry? 与不同商店(UserStore,UserEmailStore,UserClaimStore,UserLockoutStore等)一起使用的UserManager - UserManager used with different stores (UserStore, UserEmailStore, UserClaimStore, UserLockoutStore etc.) 如何使用Asp.net C#打开没有下载选项的任何类型的文件(PDF,Excel,doc等) - How to open any type (PDF,excel,doc etc.) of file without download option using Asp.net c# 具有泛型类型的函数中使用的Ordeby(),Where()等 - Ordeby(), Where(), etc. used in a function with generic types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM