How do I modify colors like Windows does to make 3D border slightly darker or lighter?

J

jrhoads23

If you look at a standard Button in a .NET Windows Forms app, you will
notice its default BackColor is "Control" and it has a 3D raised border
which is 2 pixels wide. The outer edge on the left and top is
"ControlLightLight" color and the inner edge on the left and top is
"ControlLight". The outer edge on the right and bottom is
"ControlDarkDark" and the inner edge on the right and bottom is
"ControlDark". All of these colors are defined as KnownColors in the
System.Drawing namespace.

My question is this, when you change the BackColor of the button to
"Red", the border colors are adjusted as well. The top and left is made
slightly lighter versions of red while the bottom and right are made
slightly darker versions of red.

How can I take a given color such as Red, Green, ... and get their
slightly lighter and darker versions? There doesnt appear to be any
methods in the Color structure or ColorConverter class.

Any ideas?
 
H

Herfried K. Wagner [MVP]

How can I take a given color such as Red, Green, ... and get their
slightly lighter and darker versions? There doesnt appear to be any
methods in the Color structure or ColorConverter class.

'ControlPaint.Dark'
'ControlPaint.DarkDark'
'ControlPaint.Light'
'ControlPaint.LightLight'
 
J

Jay B. Harlow [MVP - Outlook]

jrhoads23,
As Tim suggests I use System.Windows.Forms.ControlPaint.

Specifically:
- ControlPaint.Dark
- ControlPaint.DarkDark
- ControlPaint.Light
- ControlPaint.LightLight

Something like:

Dim lightBackColor As Color = ControlPaint.Light(BackColor)
Dim lightLightBackColor As Color = ControlPaint.LightLight(BackColor)
Dim darkBackColor As Color = ControlPaint.Dark(BackColor)
Dim darkDarkBackColor As Color = ControlPaint.DarkDark(BackColor)


Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top