Professional Documents
Culture Documents
#Region "SetDefaultPrinter"
'現在の通常使うプリンタ名取得
strDefaultPrinter = pd.PrinterSettings.PrinterName
If printerName = strDefaultPrinter Then Return True
'通常使うプリンタに設定に成功
If pd.PrinterSettings.IsValid Then
strDefaultPrinter = printerName
Return True
End If
End If
Next
'通常使うプリンタに設定に失敗
Dim strLogMsg As String =
String.Format(_DataAccess.GetMessage("HAID000037"), printerName)
_Logger.Write(Common.LogLevels.Warn, sectionName, strLogMsg)
'メッセージ表示
'メッセージスタイル設定
style = MsgBoxStyle.DefaultButton1 Or _
MsgBoxStyle.Exclamation Or MsgBoxStyle.YesNo
title = "通常使うプリンタに設定"
msg = String.Format(_DataAccess.GetMessage("HAID000038"), printerName,
strDefaultPrinter)
msg = msg.Replace("\n", vbNewLine)
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
'現在の通常使うプリンタで印刷
Return True
End If
'印刷続行しない
Return False
End Function
'プリンタを列挙する
Dim mo As New ManagementObject
For Each mo In moc
If CBool(mo("Default")) Then
strDefaultPrinter = CStr(mo("Name"))
End If
If CStr(mo("Name")) = printerName Then
'名前を見つけたとき、デフォルトプリンタに設定する
Dim mbo As ManagementBaseObject =
mo.InvokeMethod("SetDefaultPrinter", Nothing, Nothing)
Dim ret As Long = Convert.ToInt64(mbo("returnValue"))
If ret = 0 Then
'通常使用するプリンタ設定に成功、処理終了
strDefaultPrinter = printerName
bFound = True
End If
End If
Next mo
Dim msg As String 'メッセージ領域
'メッセージ表示
If Not bFound Then
'通常使用するプリンタ設定に失敗
_Logger.Write(Common.LogLevels.Warn, sectionName, strLogMsg)
'メッセージスタイル設定
style = MsgBoxStyle.DefaultButton1 Or _
MsgBoxStyle.Exclamation Or MsgBoxStyle.YesNo
title = "通常使うプリンタに設定"
msg = String.Format(_DataAccess.GetMessage("HAID000038"), printerName,
strDefaultPrinter)
msg = msg.Replace("\n", vbNewLine)