?
Solved

Print in WPF

Posted on 2011-09-27
3
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 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