GDI Drawing Text with outline and shadow

  • Thread starter Thread starter Lou
  • Start date Start date
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
 
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
----------------
 
Back
Top