As an alternative to rendering a blurry shadow, a more user-friendly option would be to render the shadow slightly shifted down and to the right (as you originally intended), but with alpha transparency so that the shadow does not seem so βhardβ:
protected void RenderDropshadowText( Graphics graphics, string text, Font font, Color foreground, Color shadow, int shadowAlpha, PointF location) { const int DISTANCE = 2; for (int offset = 1; 0 <= offset; offset--) { Color color = ((offset < 1) ? foreground : Color.FromArgb(shadowAlpha, shadow)); using (var brush = new SolidBrush(color)) { var point = new PointF() { X = location.X + (offset * DISTANCE), Y = location.Y + (offset * DISTANCE) }; graphics.DrawString(text, font, brush, point); } } }
To give an example of how this will be called from code, for example, in the OnPaint method:
RenderDropshadowText(e.Graphics, "Dropshadow Text", this.Font, Color.MidnightBlue, Color.DimGray, 64, new PointF(10, 10));
To nudge things a bit and get a more convincing shadow effect, we could modify the above function to simulate the blur effect by slightly drawing text with additional alpha transparency, once to the left and once slightly to the right of the shadow:
if (offset > 0) { using (var blurBrush = new SolidBrush(Color.FromArgb((shadowAlpha / 2), color))) { graphics.DrawString(text, font, blurBrush, (point.X + 1), point.Y); graphics.DrawString(text, font, blurBrush, (point.X - 1), point.Y); } }
Here is a screenshot of the final result:
