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
whole paint event is as followCode:Dim tbm As Bitmap = CType(bm.Clone, Bitmap)
i have converted this program from an other program which ads text on the form to a pre-assigned picture on the formCode: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
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




Reply With Quote