Beispiel #1
0
        private bool IsPrinterAvailable(string driverName)
        {
            ZBRPrinter printer = null;
            try {
                printer = new ZBRPrinter();
                int error = 0;

                int result = printer.Open(driverName, out error);
                if ((result == 1) && (error == 0)) {
                    return true;
                }
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
            } finally {
                printer = null;
            }
            return false;
        }
Beispiel #2
0
        private bool IsPrinterAvailable(string driverName)
        {
            //boolean method to test whether the printer is available using driverName parameter
            ZBRPrinter printer = null; //creates printer variable from the ZBRPrinter.cs class initialized to null
            try {
                printer = new ZBRPrinter(); //creates new ZBRPrinter object and stores in printer
                int error = 0; //initial value of errors is 0 meaning printer is available, but will change if errors are detected

                int result = printer.Open(driverName, out error); //passes IsPrinterAvailable method param as an argument to Open method of printer object and stores in result variable
                if ((result == 1) && (error == 0)) { //if the result variable is set to 1 and there are no errors...
                    return true; //return true - the printer is available
                }
            } catch (Exception e) { //exception handler
                MessageBox.Show(e.ToString()); //catches and displays resulting errors to prevent program crash
            } finally { //finally block runs whether there is an exception or not
                printer = null; //sets printer object to null after it has been used to determine if printer is available
            }
            return false; //else return false - the printer is unavailable
        }