I am making drawing form. I already made it and I am able to draw on the form. I want to make one button which will save image of drawing form. So, draw on the form then save as JPEG in C drive. Does anybody have idea how to make this?
Sub Form_Paint(sender, e) Handles Me.Paint
MyDrawing(e.Graphics)
End Sub
Sub MyDrawing(g As Graphics)
g.DrawThis()
g.DrawThat()
End Sub
Sub SaveImage()
Dim bmp As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
MyDrawing(g)
g.Dispose()
bmp.Save("filename.bmp")
bmp.Dispose()
End Sub
Sub SaveButton_Click(sender,e) Handles SaveButton.Click
SaveImage()
End Sub
The point of using the Paint event is that what you draw there is what is drawn and nothing else. If you're using Paint event (as you should) then what you explain is not possible unless you are drawing at two locations for each call of Paint event, or invalidating wrong areas. To control a location from elsewhere than Paint event handler it must be declared at a higher level than locally in the method, like this:t, I'm able to draw the piece only on the new position and am unable to delete the image from the old position.
Private p As Point
Sub MyDrawing(g As Graphics)
g.DrawThis(p)
g.DrawThat(p)
End Sub
Sub Timer_Tick(sender,e) Handles timer.Tick
p.x += 1
Me.Refresh()
End Sub