CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Mar 2008
    Posts
    142

    text and picture problem

    i m writing a small program to add text on the picture box
    but when i run my program...then this error comes"Object reference not set to an instance of an object." on the following line
    Code:
     Dim tbm As Bitmap = CType(bm.Clone, Bitmap)
    whole paint event is as follow
    Code:
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
            Dim tbm As Bitmap = CType(bm.Clone, Bitmap)
            Dim g As Graphics = Graphics.FromImage(tbm)
            Dim mx As Matrix = New Matrix
            Dim gpathText As New GraphicsPath
            Dim br As SolidBrush = New SolidBrush(Color.FromArgb(tbarTrans.Value, _
                                                  Color.LightCoral))
    
            'Smooth the Text
            g.SmoothingMode = SmoothingMode.AntiAlias
    
            'Make the GraphicsPath for the Text
            Dim emsize As Single = Me.CreateGraphics.DpiY * pic_font.SizeInPoints / 72
            'gpathText.AddString(strText, pic_font.FontFamily, CInt(pic_font.Style), _
            ' emsize, New RectangleF(ptText.X, ptText.Y, szText.Width, szText.Height), _
            ' StringFormat.GenericDefault)
    
            'Draw a copy of the image to the Graphics Object canvas
            g.DrawImage(CType(bm.Clone, Bitmap), 0, 0)
    
            'Rotate the Matrix at the center point
            mx.RotateAt(tbarRotate.Value, _
                New Point(ptText.X + (szText.Width / 2), ptText.Y + (szText.Height / 2)))
    
            'Get the points for the rotated text bounds
            mx.TransformPoints(ptsText)
    
            'Transform the Graphics Object with the Matrix
            g.Transform = mx
    
            'Draw the Rotated Text
            g.FillPath(br, gpathText)
            If chkAddOutline.Checked Then
                Using pn As Pen = New Pen(Color.FromArgb(tbarTrans.Value, Color.White), 1)
                    g.DrawPath(pn, gpathText)
                End Using
            End If
    
            'Draw the box if the mouse is over the Text
            If MouseOver Then
                g.ResetTransform()
                g.DrawPolygon(ptsTextPen, ptsText)
            End If
    
            'Draw the whole thing to the form
            e.Graphics.DrawImage(tbm, 10, 10)
    
            tbm.Dispose()
            g.Dispose()
            mx.Dispose()
            br.Dispose()
            gpathText.Dispose()
        End Sub
    i have converted this program from an other program which ads text on the form to a pre-assigned picture on the form
    but i have converted it into a picture box
    i have added a picture box and calling its paint event while in the original program..form pain event is called
    attaching the file
    kindly help me
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured