Windows CE 开发
//--------------------------------------------------------------------
// FILENAME: ReaderForm2.cs
//
// Copyright(c) 2004 Symbol Technologies Inc. All rights reserved.
//
// DESCRIPTION:
//
// NOTES:
//
//
//--------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace CS_ScanSample3
{
/// <summary>
/// Summary description for ReaderForm2.
/// </summary>
public class ReaderForm2 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox ReaderDataTextBox;
private System.Windows.Forms.Button ReaderForm2Button;
private System.EventHandler ReaderForm2EventHandler;
public ReaderForm2()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ReaderDataTextBox = new System.Windows.Forms.TextBox();
this.ReaderForm2Button = new System.Windows.Forms.Button();
//
// ReaderDataTextBox
//
this.ReaderDataTextBox.Location = new System.Drawing.Point(24, 24);
this.ReaderDataTextBox.Size = new System.Drawing.Size(184, 22);
this.ReaderDataTextBox.Text = "";
//
// ReaderForm2Button
//
this.ReaderForm2Button.Location = new System.Drawing.Point(72, 120);
this.ReaderForm2Button.Size = new System.Drawing.Size(88, 25);
this.ReaderForm2Button.Text = "Main Form";
this.ReaderForm2Button.Click += new System.EventHandler(this.ReaderForm2Button_Click);
//
// ReaderForm2
//
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(240, 270);
this.Controls.Add(this.ReaderForm2Button);
this.Controls.Add(this.ReaderDataTextBox);
this.Text = "ReaderForm2";
this.Load += new System.EventHandler(this.ReaderForm2_Load);
}
#endregion
/// <summary>
/// Occurs before the form is displayed for the first time.
/// </summary>
private void ReaderForm2_Load(object sender, System.EventArgs e)
{
// Create a new delegate to handle scan notifications
ReaderForm2EventHandler = new EventHandler(ReaderForm2_ReadNotify);
// Set the event handler of the Scanning class to our delegate
Scanning.MyEventHandler = ReaderForm2EventHandler;
// Attach to activate and deactivate events
this.Activated +=new EventHandler(ReaderForm2_Activated);
// Start a read on the reader
Scanning.StartRead();
}
/// <summary>
/// Read complete or failure notification
/// </summary>
private void ReaderForm2_ReadNotify(object sender, EventArgs e)
{
Symbol.Barcode.ReaderData TheReaderData = Scanning.MyReaderData;
// If it is a successful read (as opposed to a failed one)
if ( TheReaderData.Result == Symbol.Results.SUCCESS )
{
// Display the data from this read into the text box
ReaderDataTextBox.Text = TheReaderData.Text;
// Start the next read
Scanning.StartRead();
}
}
/// <summary>
/// Called when the form is activated. Never called in this sample since
/// ReaderForm2 is invoked as a modal dialog.
/// </summary>
private void ReaderForm2_Activated(object sender, EventArgs e)
{
// Reset the scan event handler for the Scanning object everytime the form is activated
Scanning.MyEventHandler = ReaderForm2EventHandler;
// Start the next read
Scanning.StartRead();
}
/// <summary>
/// Called upon the press of "Main Form" Button and causes ReaderForm2 to close.
/// </summary>
private void ReaderForm2Button_Click(object sender, System.EventArgs e)
{
// Cancel the read
Scanning.StopRead();
// Exit this form
this.Close();
}
}
}