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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

jampostGeneral MaanagerAuthor Commented:
lenordiste,




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

-----Now it wants an object reference____
0
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.