Search code examples
vb.netprintdocumentmy.settings

How to save drawing to PrintDocument Item on My.Settings?


Is there any way to draw on System.Drawings.Printing.PrintDocument item in My.Settings, lets name it as LastDocument.

I found that we can set it as same document of other PrintDocuments on Application forms which doesn't help me in this case. What I want is, the item, LastDocument, should save drawings from my selected PrintDocument from my Application form and retrieve it later.

So is there any method to do this.

I found one partial solution is to save the PrintDocument drawings as an image to My.Settings using the method mentioned by John here.


Solution

  • Thank you jmcilhinney for your help. Now as I solved the problem per your guidelines and as I have solved it for me I took decision to write the answer what I did to solve the issue so the future viewers find it easy to solve.

    1. Double click on 'My Project' from 'Solution Explorer' and go to 'Settings', add new item with some name, here I will use LastDocument, and 'Type' as 'String'. Save all and close the tab.

    2. Back to your form from where you want to save the image to My.Settings.LastDocument and add this line to save the image to My.Settings.LastDocument,

      Dim mstream As New System.IO.MemoryStream pic.Image.Save(mstream, Imaging.ImageFormat.Png) Dim arrimage() As Byte = mstream.GetBuffer My.Settings.LastDocument = Convert.ToBase64String(arrimage)

    3. Now to get the picture back from settings use this,

      Dim arrimage() As Byte = Convert.FromBase64String(My.Settings.LastDocument) Dim mstream As New System.IO.MemoryStream(arrimage) Dim GetLastImg As Bitmap = New Bitmap(System.Drawing.Image.FromStream(mstream)) pic.Image = GetLastImg