How to relate to the BG-color, which is used by some elements of Windows (scroll button, power button, etc.)?

Does anyone know how I can refer to C # on the background color of the system used on elements such as the scroll button or the pressed button or tab (as the background for "tabPage1" in the image below)? Or, if a predefined constant does not exist, any algorithm, how to create a brush with this color? Thanks!

background for tabPage1 indicates desired color

My intuitive first choice of SystemColors.ScrollBar is the same as .Control or .ButtonFace (BG for "tabPage2"), which is really the "face" for the scroll bar, and not what I would call the "background".
SystemColors.ControlLight or SystemColors.ControlLightLight not approaching.

When you zoom in, this area of ​​the control looks like a control panel with .Control and .Window pixels, so for me this hints at the possibility of smoothing this color; perhaps this indicates why the standard SystemColors enum does not define it? How to apply it to another control?

zoomed-in view exposes the dithering

PS: I'm trying to improve a custom TabControl (which supports disabled tabs is another good thing missing from std controls, but this is another and already resolved story), so when its .Appearance set to Buttons or FlatButtons , it looks like the original ( see above). The selected tab is displayed with the pressed button, but its background color is set to Control or ButtonFace :

enter image description here

+4
source share
2 answers

Well, that turned out to be a lot easier than I thought - it's about Brush used to populate BG-rect:

 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 the using( Brush br= new .. ) {..} block cannot be applied, since initialization differs in the resulting type of the object. Hence the somewhat ugly try-finally . It works like a charm!

+1
source

I'm sorry that I don't know Forms very well, but MFC has a function to provide such fading bitmaps ( AfxGetDitheredBitmap ), so I guess you will need to do something like this.

Unfortunately, I could not find an equivalent .Net function, sorry.

0
source

Source: https://habr.com/ru/post/1395295/


All Articles