GDI w/ UserControl question

daktmacfan

New member
Joined
Mar 13, 2008
Messages
1
Programming Experience
1-3
Hi,

I have developed a chart control in VB.NET that is drawn with GDI+.

I want to make the current charts image to be a public property of type Image.

I cannot figure out how to do this.

Here is kind how my drawing function is setup:


Private Sub DoPaint(ByVal canvas As Graphics)

'somedrawing

canvas.DrawLine()
canvas.DrawLine()

canvas.DrawText()

'now I would like to save all that I have drawn
'to an Image ojbect

'not sure how to do something such as this
Dim temp As Image = ???
End Sub

thanks,
David
 
You have to draw the same thing to a Bitmap.
VB.NET:
Dim bmp As New Bitmap(Height, Width)
Using g As Graphics = Graphics.FromImage(bmp)
    'draw
End Using
 
I would use this:

VB.NET:
'the paint routine
dim bmp as new bitmap(me.clientrectangle.width, me.clientrectangle.height)
dim g as graphics=graphics.fromimage(bmp)
'do drawing stuff
me.backgroundimage=bmp

you could then exploit the image because it is saved in the backgroundimage property of your usercontrol
 
Back
Top