[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Print in WPF

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
VBdotnet2005
Asked:
VBdotnet2005
1 Solution
 
VBdotnet2005Author Commented:
I forgot to add. My labels are on in Tab #2 and in Groupbox.
0
 
Bob LearnedCommented:
There is not enough context to understand how you called it when it wasn't in a button click event handler.
0
 
CodeCruiserCommented:
I think tabs are only created/initialized when they get focus for the first time so that may be your issue.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now