none
print rectangle that draw in panel RRS feed

  • Question

  • HI

    I have a a form that contain a panel.

    I draw a rectangle in panel programmatically . when i print the panel , rectangle dose not show in print page

    how can i do it?

    draw rectangle :

    Dim g1 As Graphics = Panel1.CreateGraphics
            g1.DrawRectangle(Pens.Black, 30, 80, 700, 400)
           
            g1.Dispose()

     

    print panel :

     

     bmp = New Bitmap(Panel1.ClientRectangle.Width, Panel1.ClientRectangle.Height)
            Dim G As Graphics = Graphics.FromImage(bmp)
            Panel1.DrawToBitmap(bmp, Panel1.ClientRectangle)
            G.Dispose()
           
            PrintPreviewDialog1.Document = PrintDocument1
            PrintPreviewDialog1.ShowDialog()

     

     Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
           
            e.Graphics.DrawImage(bmp, 0, 0)

        End Sub

    Thursday, November 25, 2010 8:12 PM

Answers

  • You either must use persistent graphics, i.e., the graphics supplied in the Paint event of the panel,  or explicitly draw the rectangle in the PrintPage event.  Using CreatGraphics for purposes other than measurement is generally a bad idea.
    • Proposed as answer by eryang Saturday, November 27, 2010 6:40 AM
    • Marked as answer by eryang Sunday, November 28, 2010 5:04 AM
    Thursday, November 25, 2010 9:12 PM

All replies

  • You either must use persistent graphics, i.e., the graphics supplied in the Paint event of the panel,  or explicitly draw the rectangle in the PrintPage event.  Using CreatGraphics for purposes other than measurement is generally a bad idea.
    • Proposed as answer by eryang Saturday, November 27, 2010 6:40 AM
    • Marked as answer by eryang Sunday, November 28, 2010 5:04 AM
    Thursday, November 25, 2010 9:12 PM
  • please  send a sample code
    Thursday, November 25, 2010 10:29 PM
  • please  send a sample code

    You want Rent-A-Coder.
    Thursday, November 25, 2010 10:40 PM
  • You may also ask the question at  Windows Forms forum  for better support.

    We temporarily mark a reply, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Sunday, November 28, 2010 5:02 AM