Click here to Skip to main content
13,044,935 members (40,602 online)
Rate this:
Please Sign up or sign in to vote.
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 10-Sep-10 10:35am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 10 Sep 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100