I need to print a WPF form

         The environment is      [Visual Studio 2008   /    Visual Basic 2008 /  WPF application]    I need to print a WPF form. I am printing 20 labels  --  2 vertical rows of 10. They  are 1” Height by 4” wide.  The Windows form has limited height, so I am using WPF  (no problem on the 20 labels), but, does not offer the user friendly “print form” control, and that is where I am stuck.
jampostGeneral MaanagerAsked:
Who is Participating?
 
lenordisteCommented:
"myCanvas" is just an example, you can use any of the controls you are using in WPF (a grid for example) since PrintVisual() expects a Visual type object as parameter. Also, you need to instantiate PrintDialog.

Here is how (i ll use the reference "me" since it's probably a reference to the window you are working on):
  Dim printDiag As New PrintDialog()
        printDiag.PrintVisual(Me, "a description")

Open in new window


0
 
lenordisteCommented:
you can simply use this, where the variable "myCanvas" is your actual canvas:
PrintDialog.PrintVisual(myCanvas,"your description");

Open in new window


and if you need to display a print dialog:
 var printDiag = new PrintDialog();
  if (printDiag.ShowDialog())
  { printDiag.PrintVisual(myCanvas, "your description"); }

Open in new window


also in WPF you can print any visuals, so you can just pass any reference to the PrintVisual method as long as it derives from visuals.
0
 
jampostGeneral MaanagerAuthor Commented:
lenordiste,

Are you saying that I can add this in the VB code as a Private Sub with the following sentax?

Private Sub BtnPrint_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnPrint.Click

PrintDialog.PrintVisual(myCanvas,"your description");

End Sub

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
jampostGeneral MaanagerAuthor Commented:
 It looks like I might have a sentax problem in two areas.

     The first problem is that mycanvas is not declared.
     Dim mycanvas As  (what type?)
     The other problem is   ;    which I removed, so maybe if I can sucessfully declare mycanvas then it will be show time.  Do you know what type I should use?    

       Thanks again for your help     Joe
0
 
jampostGeneral MaanagerAuthor Commented:
lenordiste,




Dim mycanvas As String
        PrintDialog.PrintVisual(myCanvas, "your description")

-----Now it wants an object reference____
0
 
jampostGeneral MaanagerAuthor Commented:
lenordiste,

I put the declaration at the top:

Class SA_prt
Dim PrintDialog As New PrintDialog()
______________________________________________


Public Sub BtnPrint_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnPrint.Click

        PrintDialog.PrintVisual(Window1, "PRT")

    End Sub



I am far enough along that I can take it from here.  It is printing. It just needs some alignment now. That, I can tweek.  Thank you
0
 
jampostGeneral MaanagerAuthor Commented:
Thank you,

WPF  is OK after you get use to it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.