Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi !
I sought much, but without success.
I have a rounded rectangle made with a GraphicsPath and I want to have an inner bevel like in Photoshop.
I can easilly drawing an "inner shadow" effect using a PathGradientBrush.
The inner shadow is a good effect, but have only one color.

Nobody on the web seems to have an answer.

Thanks for your ideas
Posted

1 solution

There are two things to take into account when drawing bevels:

1. the "lighting effect" behaves one way on the upper left half of the object, and the other way on the lower right half (brightening the UL, darkening the LR).

2. you need multiple, nested, similar paths, that are inset from each other by a single pixel all around (because, typically, bevels are drawn 2 pixels wide).

To address #1 you need to (a) figure out your darker and lighter colors, and (b) split the graphics path in to a pair of UL & LR parts. You will also need (for #2) the exact pixel height and width of the path.

To address #2, you need to use GDI+'s transform to scale the path by exactly 2 pixels in height and width, and to offset the scaled path by exactly 1 pixel - so that the new path fits exactly inside the original.

Now you have four "half paths", with a pair that fits inside the other pair, that you can render light/normal/dark/super-dark. I would use Windows' magnifier to see the color arrangement of beveled controls to get an idea of what colors to use where.

You're probably going to have to tweak your paths so that they join correctly at the 'cut' ends between the UL and LR parts; given that you have rounded corners, you may also find that you need to do something extra at the cut corners to make an acceptable gradient from light to dark (with square cornered boxes this is never an issue). You may may need to make special corner segments to handle this.
 
Share this answer
 
Comments
Member 14650948 17-Nov-23 11:26am    
This would be great if you could make it a "Custom Control".
Then, I could use it in WinForm projects I work on (not WPF).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900