VBdotnet2005
asked on
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("Set DefaultPri nter", New Object() {"HP 2000"})
printer.InvokeMethod("SetD efaultPrin ter", New Object() {"HP 2000"})
Exit For
End If
Next
printDialog.PrintVisual(Me .GroupBox4 , "Printing Header")
End Sub
Public Sub Printnow()
Dim printDialog As New PrintDialog()
Dim query = New ManagementObjectSearcher("
Dim printers = query.Get
For Each printer As ManagementObject In printers 'loop to get Printer name
If printer("name").ToString()
'printer.InvokeMethod("Set
printer.InvokeMethod("SetD
Exit For
End If
Next
printDialog.PrintVisual(Me
End Sub
There is not enough context to understand how you called it when it wasn't in a button click event handler.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER