大家好,又见面了,我是你们的朋友全栈君。
首先声明一个打印机状态枚举:
public enum PrinterStatus
{
[Description(“其他状态”)]
Other = 1,
[Description(“未知”)]
Unknown = 2,
[Description(“空闲”)]
Idle = 3,
[Description(“正在打印”)]
Printing = 4,
[Description(“预热”)]
Warmup = 5,
[Description(“停止打印”)]
Stopped = 6,
[Description(“离线”)]
Offline = 7
}
获取打印机设备当前状态方法:
/// <summary>
/// 根据打印设备名获取该打印机当前状态
/// </summary>
/// <param name=”PrinterDevice”>设备名</param>
/// <returns>返回打印机状态枚举</returns>
public static PrinterStatus GetPrinterStatus(string PrinterDevice)
{
PrinterStatus ret = 0;
string path = @”win32_printer.DeviceId='” + PrinterDevice + “‘”;
ManagementObject printer = new ManagementObject(path);
printer.Get();
ret = (PrinterStatus)Convert.ToInt32(printer.Properties[“PrinterStatus”].Value);
return ret;
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/155515.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...