Solved

Print in WPF

Posted on 2011-09-27
3
220 Views
Last Modified: 2012-05-12
I have a sub below to print in WPF. When I call it, it won't print. However, when I put the code under button 1, it prints. Not sure why.



Public Sub Printnow()
        Dim printDialog As New PrintDialog()
        Dim query = New ManagementObjectSearcher("SELECT *FROM Win32_Printer")
        Dim printers = query.Get
        For Each printer As ManagementObject In printers   'loop to get Printer name
            If printer("name").ToString() = "HP 2000" Then
                'printer.InvokeMethod("SetDefaultPrinter", New Object() {"HP 2000"})
                printer.InvokeMethod("SetDefaultPrinter", New Object() {"HP 2000"})
                Exit For
            End If
        Next
        printDialog.PrintVisual(Me.GroupBox4, "Printing Header")

    End Sub
0
Comment
Question by:VBdotnet2005
3 Comments
 

Author Comment

by:VBdotnet2005
ID: 36712760
I forgot to add. My labels are on in Tab #2 and in Groupbox.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 36717343
There is not enough context to understand how you called it when it wasn't in a button click event handler.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 36718961
I think tabs are only created/initialized when they get focus for the first time so that may be your issue.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now