title: need help = using class with barcode scanning
body: <p>i have this code from Motorola that can scann barcode in Windows-CE</p>
  
  <p>it works excellent, but how to make any class that all my forms can work with</p>
  
  <p>this scanner ?</p>
  
  <p>the scanner class:</p>
  
  <pre><code>using System;
  using System.Data;
  using System.IO;
  using System.Windows.Forms;
  
  
  namespace MyScann
  {
      /// &lt;summary&gt;
      /// Summary description for Scanner.
      /// &lt;/summary&gt;
      public class Scanner
      {
  
          public static Symbol.Barcode.Reader SymbolReader = null;
          public static Symbol.Barcode.ReaderData SymbolReaderData = null;
          public static System.EventHandler SymbolEventHandler = null;
          public static DataSet CodeDataSet;
  
  
          //public static Utils.Sound ReadErrorSound;
  
          public static bool ScannerEnabled = false;
          public static void ActivateScanner()
          {
  
              // If we have both a reader and a reader-data Object
              if ( Scanner.SymbolReader != null &amp;&amp;
                  Scanner.SymbolReaderData != null &amp;&amp;
                  ! Scanner.SymbolReaderData.IsPending )
              {
                  // Submit 'Read'
                  try
                  {
                      Scanner.SymbolReader.Actions.Read(Scanner.SymbolReaderData);
                  }
                  catch (Exception err)
                  {
                      MessageBox.Show(err.Message);
                      if ( err.InnerException != null )
                          MessageBox.Show(err.InnerException.Message);
                  }
              }
  
          }
  
          public static void DeactivateScanner()
          {
  
              // If we have both a reader and a reader-data Object
              if ( Scanner.SymbolReader != null &amp;&amp;
                  Scanner.SymbolReaderData != null &amp;&amp;
                  Scanner.SymbolReaderData.IsPending )
              {
                  // Submit 'CancelRead'
                  try
                  {
                      Scanner.SymbolReader.Actions.CancelRead(Scanner.SymbolReaderData);
                  }
                  catch (Exception err)
                  {
                      MessageBox.Show(err.Message);
                      if ( err.InnerException != null )
                          MessageBox.Show(err.InnerException.Message);
                  }
              }
  
          }
  
          /// &lt;summary&gt;
          /// Initialize the reader.
          /// &lt;/summary&gt;
          /// &lt;returns&gt;False if an error accurs&lt;/returns&gt;
          public static bool InitSymbolReader()
          {
  
              // If reader is already present then fail initialize
              if ( SymbolReader != null )
              {
                  return false;
  
               }
  
              // Create new reader, first available reader will be used.
              SymbolReader = new Symbol.Barcode.Reader();
              // Create reader data
              SymbolReaderData = new Symbol.Barcode.ReaderData(
                  Symbol.Barcode.ReaderDataTypes.Text,
                  Symbol.Barcode.ReaderDataLengths.DefaultText);
  
  
              // set scanner read error sound
              //ReadErrorSound = new Utils.Sound(ErrorSound);
  
              return true;
          }
  
          /// &lt;summary&gt;
          /// Stop reading and disable/close reader
          /// &lt;/summary&gt;
          public static void DeinitSymbolReader()
          {
              try
              {
                  // If we have a reader
                  if ( SymbolReader != null )
                  {
                      // Disable the reader
                      SymbolReader.Actions.Disable();
  
                      // Free it up
                      SymbolReader.Dispose();
  
                      // Indicate we no longer have one
                      SymbolReader = null;
                  }
  
                  // If we have a reader data
                  if ( SymbolReaderData != null )
                  {
                      // Free it up
                      SymbolReaderData.Dispose();
  
                      // Indicate we no longer have one
                      SymbolReaderData = null;
                  }
              }
              catch {}
          }
  
          /// &lt;summary&gt;
          /// Enable most barcode type with no limitation on length
          /// &lt;/summary&gt;
          public static void OpenAllBarcodes()
          {
              SymbolReader.Decoders.CODABAR.Enabled = true;
              SymbolReader.Decoders.CODABAR.MinimumLength = 0;
              SymbolReader.Decoders.CODABAR.MaximumLength = 0;
  
              SymbolReader.Decoders.CODE11.Enabled = true;
              SymbolReader.Decoders.CODE11.MinimumLength = 0;
              SymbolReader.Decoders.CODE11.MaximumLength = 0;
  
              SymbolReader.Decoders.CODE39.Enabled = true;
              SymbolReader.Decoders.CODE39.MinimumLength = 0;
              SymbolReader.Decoders.CODE39.MaximumLength = 0;
  
              SymbolReader.Decoders.CODE93.Enabled = true;
              SymbolReader.Decoders.CODE93.MinimumLength = 0;
              SymbolReader.Decoders.CODE93.MaximumLength = 0;
  
              SymbolReader.Decoders.CODE128.Enabled = true;
              SymbolReader.Decoders.CODE128.MinimumLength = 0;
              SymbolReader.Decoders.CODE128.MaximumLength = 0;
  
              SymbolReader.Decoders.DATAMATRIX.Enabled = true;
              SymbolReader.Decoders.DATAMATRIX.MinimumLength = 0;
              SymbolReader.Decoders.DATAMATRIX.MaximumLength = 0;
  
              SymbolReader.Decoders.D2OF5.Enabled = true;
              SymbolReader.Decoders.D2OF5.MinimumLength = 0;
              SymbolReader.Decoders.D2OF5.MaximumLength = 0;
  
              SymbolReader.Decoders.I2OF5.Enabled = true;
              SymbolReader.Decoders.I2OF5.MinimumLength = 0;
              SymbolReader.Decoders.I2OF5.MaximumLength = 0;
  
              SymbolReader.Decoders.EAN13.Enabled = true;
              SymbolReader.Decoders.EAN13.MinimumLength = 0;
              SymbolReader.Decoders.EAN13.MaximumLength = 0;
  
              SymbolReader.Decoders.EAN8.Enabled = true;
              SymbolReader.Decoders.EAN8.MinimumLength = 0;
              SymbolReader.Decoders.EAN8.MaximumLength = 0;
  
              SymbolReader.Decoders.PDF417.Enabled = true;
              SymbolReader.Decoders.PDF417.MinimumLength = 0;
              SymbolReader.Decoders.PDF417.MaximumLength = 0;
  
              SymbolReader.Decoders.UPCA.Enabled = true;
              SymbolReader.Decoders.UPCA.MinimumLength = 0;
              SymbolReader.Decoders.UPCA.MaximumLength = 0;
  
              SymbolReader.Decoders.UPCE1.Enabled = true;
              SymbolReader.Decoders.UPCE1.MinimumLength = 0;
              SymbolReader.Decoders.UPCE1.MaximumLength =0;
  
              SymbolReader.Decoders.UPCE0.Enabled = true;
              SymbolReader.Decoders.UPCE0.MinimumLength = 0;
              SymbolReader.Decoders.UPCE0.MaximumLength = 0;
  
  
  
  
  
              SymbolReader.Parameters.CodeIdType = Symbol.Barcode.CodeIdTypes.None;
              SymbolReader.Parameters.ScanType = Symbol.Barcode.ScanTypes.Background;
              SymbolReader.Parameters.LocalFeedback = Symbol.Barcode.DisabledEnabled.Enabled;
  
              Scanner.SymbolReader.Parameters.Feedback.Success.BeepTime = 0;
          }
  
  
  
  
  
  
  
      }
  }
  </code></pre>
  
  <p>what i use in my form:</p>
  
  <pre><code> public void InitScanner(byte BatteryLevel)
          {
  
              // Create event handler delegate
              if (Scanner.SymbolEventHandler == null)
              {
                  Scanner.SymbolEventHandler = new EventHandler(this.SymbolReader_ReadNotify);
                  // Enable reader, with wait cursor
                  Scanner.SymbolReader.Actions.Enable();
                  Scanner.OpenAllBarcodes();
                  Scanner.ScannerEnabled = true;
              }
              // If we have both a reader and a reader data
              if ((Scanner.SymbolReader != null) &amp;&amp;
                  (Scanner.SymbolReaderData != null))
              {
                  // Submit a read
                  Scanner.SymbolReader.ReadNotify += Scanner.SymbolEventHandler;
                  Scanner.SymbolReader.Actions.Read(Scanner.SymbolReaderData);
              }
          }
  
          public void SymbolReader_ReadNotify(object sender, EventArgs e)
          {
              Symbol.Barcode.ReaderData TheReaderData = Scanner.SymbolReader.GetNextReaderData();
              if (TheReaderData.Result == Symbol.Results.SUCCESS &amp;&amp; (txtBarcode.Focused == true))
              {
                  if (txtBarcode.Focused == true)
                  {
                      txtBarcode.Text = TheReaderData.Text.ToString();
                      SymbolReader_CycleScannerReader();
                      return;
                  }
              }
              SymbolReader_CycleScannerReader();
          }
  
          public void SymbolReader_CycleScannerReader()
          {
              Scanner.SymbolReader.Actions.Read(Scanner.SymbolReaderData);
          }
  
          public void StartScanner()
          {
              bool flag = false;
              try
              {
                  Scanner.SymbolEventHandler = null;
                  Scanner.DeinitSymbolReader();
                  Scanner.ScannerEnabled = false;
                  if (!Scanner.ScannerEnabled)
                  {
                      Scanner.SymbolEventHandler = null;
                      Scanner.InitSymbolReader();
                      InitScanner(100);
                      flag = true;
                  }
              }
              catch
              {
                  Scanner.SymbolEventHandler = null;
                  Scanner.InitSymbolReader();
                  InitScanner(100);
                  flag = true;
              }
              finally
              {
                  if (!flag)
                  {
                      MessageBox.Show("Scanner Error");
                  }
              }
          }
  
          public void CloseScanner()
          {
              Scanner.SymbolEventHandler = null;
              Scanner.DeinitSymbolReader();
          }
  </code></pre>
  
  <p>in the <code>public Main()</code> i use  <code>StartScanner();</code></p>
  
  <p>and when the program ends i use: <code>CloseScanner();</code></p>
  
  <p>i read the barcode on <code>txtBarcode</code> in my form</p>
  
  <p>thanks in advance</p>