GDI Drawing Text with outline and shadow

L

Lou

I need to have a Face,Outline and drop shadow. I am close but can't get my
code to work.
The face and outline work fine but the shadow is not sized correctly???

Dim rec As New Rectangle(PictureBox1.Left, PictureBox1.Top,
PictureBox1.Height, PictureBox1.Height)

Try

'Set the Font

Dim myFont As New Font("Arial", Me.nudFontSize.Value, FontStyle.Regular)

'Set the Graphics Buffer

Dim bm As New Bitmap(Me.ClientSize.Width \ 4, Me.ClientSize.Height \ 4)

'==== DROP SHADOW ====================

Dim g As Graphics = g.FromImage(bm)

g.TextRenderingHint = TextRenderingHint.AntiAlias

Dim mx As New Matrix(0.25F, 0, 0, 0.25F, 1, 1)

g.Transform = mx

g.DrawString(txtShortText.Text, myFont, New SolidBrush(Color.FromArgb(128,
Color.Black)), 10, 10, StringFormat.GenericTypographic)

'Clean up

g.Dispose()

e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic

e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias

e.Graphics.DrawImage(bm, Me.ClientRectangle, 0, 0, bm.Width, bm.Height,
GraphicsUnit.Pixel)

''==== EDGE/FACE ==========================

Dim pth As New GraphicsPath

e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias

e.Graphics.SmoothingMode = SmoothingMode.AntiAlias

pth.AddString(txtShortText.Text, myFont.FontFamily, 0, (myFont.Size), New
Point(10, 10), StringFormat.GenericTypographic)

'pen size is the size of the edge

Dim P As New Pen(Color.Black, 1)

'Draw the face

e.Graphics.FillPath(Brushes.White, pth)

'Draw the edge

e.Graphics.DrawPath(P, pth)

pth.Dispose()



'Clean(up)

bm.Dispose()

Catch MyError As Exception

MessageBox.Show(MyError.Message)

Finally

End Try
 
K

Ken Tucker [MVP]

Hi,

This code makes the shadow draw 1/4 size. Adjust the size here.
Dim mx As New Matrix(0.25F, 0, 0, 0.25F, 1, 1)

g.Transform = mx

Ken
----------------
 

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