Solved

Print in WPF

Posted on 2011-09-27
3
223 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

911 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

22 Experts available now in Live!

Get 1:1 Help Now