📄 readerform.cs
字号:
//--------------------------------------------------------------------
// FILENAME: ReaderForm.cs
//
// Copyright(c) 2005 Symbol Technologies Inc. All rights reserved.
//
// DESCRIPTION:
//
// NOTES:
//
//
//--------------------------------------------------------------------
using System;
using System.Windows.Forms;
namespace CS_ScanSample2
{
/// <summary>
/// CS_ScanSample2 Form class.
/// </summary>
public class ReaderForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button CodesButton;
private System.Windows.Forms.Label EventLabel;
private System.Windows.Forms.TextBox EventTextBox;
private System.Windows.Forms.Label LengthLabel;
private System.Windows.Forms.TextBox LengthTextBox;
private System.Windows.Forms.Label TimeLabel;
private System.Windows.Forms.TextBox TimeTextBox;
private System.Windows.Forms.Label SourceLabel;
private System.Windows.Forms.TextBox SourceTextBox;
private System.Windows.Forms.Label TypeLabel;
private System.Windows.Forms.TextBox TypeTextBox;
private System.Windows.Forms.Label DataLabel;
private System.Windows.Forms.TextBox DataTextBox;
private System.Windows.Forms.Button ParamsButton;
private System.Windows.Forms.Button ViewButton;
private System.Windows.Forms.Button ScanButton;
private System.Windows.Forms.Button AboutButton;
private System.Windows.Forms.Button CloseButton;
public ReaderForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.ScanButton.Focus();
}
#if COMPLETE_FRAMEWORK
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#endif
#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.CodesButton = new System.Windows.Forms.Button();
this.EventLabel = new System.Windows.Forms.Label();
this.EventTextBox = new System.Windows.Forms.TextBox();
this.LengthLabel = new System.Windows.Forms.Label();
this.LengthTextBox = new System.Windows.Forms.TextBox();
this.TimeLabel = new System.Windows.Forms.Label();
this.TimeTextBox = new System.Windows.Forms.TextBox();
this.SourceLabel = new System.Windows.Forms.Label();
this.SourceTextBox = new System.Windows.Forms.TextBox();
this.TypeLabel = new System.Windows.Forms.Label();
this.TypeTextBox = new System.Windows.Forms.TextBox();
this.DataLabel = new System.Windows.Forms.Label();
this.DataTextBox = new System.Windows.Forms.TextBox();
this.CloseButton = new System.Windows.Forms.Button();
this.ParamsButton = new System.Windows.Forms.Button();
this.ViewButton = new System.Windows.Forms.Button();
this.ScanButton = new System.Windows.Forms.Button();
this.AboutButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// CodesButton
//
this.CodesButton.Location = new System.Drawing.Point(8, 240);
this.CodesButton.Name = "CodesButton";
this.CodesButton.Size = new System.Drawing.Size(64, 25);
this.CodesButton.TabIndex = 3;
this.CodesButton.Text = "Codes";
this.CodesButton.Click += new System.EventHandler(this.CodesButton_Click);
this.CodesButton.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CodesButton_KeyDown);
//
// EventLabel
//
this.EventLabel.Location = new System.Drawing.Point(8, 176);
this.EventLabel.Name = "EventLabel";
this.EventLabel.Size = new System.Drawing.Size(72, 21);
this.EventLabel.Text = "Event:";
//
// EventTextBox
//
this.EventTextBox.Location = new System.Drawing.Point(80, 176);
this.EventTextBox.Name = "EventTextBox";
this.EventTextBox.Size = new System.Drawing.Size(152, 23);
this.EventTextBox.TabIndex = 11;
//
// LengthLabel
//
this.LengthLabel.Location = new System.Drawing.Point(8, 144);
this.LengthLabel.Name = "LengthLabel";
this.LengthLabel.Size = new System.Drawing.Size(72, 21);
this.LengthLabel.Text = "Length:";
//
// LengthTextBox
//
this.LengthTextBox.Location = new System.Drawing.Point(80, 144);
this.LengthTextBox.Name = "LengthTextBox";
this.LengthTextBox.Size = new System.Drawing.Size(152, 23);
this.LengthTextBox.TabIndex = 10;
//
// TimeLabel
//
this.TimeLabel.Location = new System.Drawing.Point(8, 112);
this.TimeLabel.Name = "TimeLabel";
this.TimeLabel.Size = new System.Drawing.Size(72, 21);
this.TimeLabel.Text = "Time:";
//
// TimeTextBox
//
this.TimeTextBox.Location = new System.Drawing.Point(80, 112);
this.TimeTextBox.Name = "TimeTextBox";
this.TimeTextBox.Size = new System.Drawing.Size(152, 23);
this.TimeTextBox.TabIndex = 9;
//
// SourceLabel
//
this.SourceLabel.Location = new System.Drawing.Point(8, 80);
this.SourceLabel.Name = "SourceLabel";
this.SourceLabel.Size = new System.Drawing.Size(72, 21);
this.SourceLabel.Text = "Source:";
//
// SourceTextBox
//
this.SourceTextBox.Location = new System.Drawing.Point(80, 80);
this.SourceTextBox.Name = "SourceTextBox";
this.SourceTextBox.Size = new System.Drawing.Size(152, 23);
this.SourceTextBox.TabIndex = 8;
//
// TypeLabel
//
this.TypeLabel.Location = new System.Drawing.Point(8, 48);
this.TypeLabel.Name = "TypeLabel";
this.TypeLabel.Size = new System.Drawing.Size(72, 21);
this.TypeLabel.Text = "Type:";
//
// TypeTextBox
//
this.TypeTextBox.Location = new System.Drawing.Point(80, 48);
this.TypeTextBox.Name = "TypeTextBox";
this.TypeTextBox.Size = new System.Drawing.Size(152, 23);
this.TypeTextBox.TabIndex = 7;
//
// DataLabel
//
this.DataLabel.Location = new System.Drawing.Point(8, 16);
this.DataLabel.Name = "DataLabel";
this.DataLabel.Size = new System.Drawing.Size(72, 21);
this.DataLabel.Text = "Data:";
//
// DataTextBox
//
this.DataTextBox.Location = new System.Drawing.Point(80, 16);
this.DataTextBox.Name = "DataTextBox";
this.DataTextBox.Size = new System.Drawing.Size(152, 23);
this.DataTextBox.TabIndex = 6;
//
// CloseButton
//
this.CloseButton.Location = new System.Drawing.Point(168, 240);
this.CloseButton.Name = "CloseButton";
this.CloseButton.Size = new System.Drawing.Size(64, 25);
this.CloseButton.TabIndex = 5;
this.CloseButton.Text = "Exit";
this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click);
this.CloseButton.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CloseButton_KeyDown);
//
// ParamsButton
//
this.ParamsButton.Location = new System.Drawing.Point(88, 240);
this.ParamsButton.Name = "ParamsButton";
this.ParamsButton.Size = new System.Drawing.Size(64, 25);
this.ParamsButton.TabIndex = 4;
this.ParamsButton.Text = "Params";
this.ParamsButton.Click += new System.EventHandler(this.ParamsButton_Click);
this.ParamsButton.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ParamsButton_KeyDown);
//
// ViewButton
//
this.ViewButton.Location = new System.Drawing.Point(168, 208);
this.ViewButton.Name = "ViewButton";
this.ViewButton.Size = new System.Drawing.Size(64, 25);
this.ViewButton.TabIndex = 2;
this.ViewButton.Text = "View";
this.ViewButton.Click += new System.EventHandler(this.ViewButton_Click);
this.ViewButton.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ViewButton_KeyDown);
//
// ScanButton
//
this.ScanButton.Location = new System.Drawing.Point(8, 208);
this.ScanButton.Name = "ScanButton";
this.ScanButton.Size = new System.Drawing.Size(64, 25);
this.ScanButton.TabIndex = 0;
this.ScanButton.Text = "Scan";
this.ScanButton.Click += new System.EventHandler(this.ScanButton_Click);
this.ScanButton.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ScanButton_KeyDown);
//
// AboutButton
//
this.AboutButton.Location = new System.Drawing.Point(88, 208);
this.AboutButton.Name = "AboutButton";
this.AboutButton.Size = new System.Drawing.Size(64, 25);
this.AboutButton.TabIndex = 1;
this.AboutButton.Text = "About";
this.AboutButton.Click += new System.EventHandler(this.AboutButton_Click);
this.AboutButton.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AboutButton_KeyDown);
//
// ReaderForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(240, 270);
this.Controls.Add(this.ScanButton);
this.Controls.Add(this.ViewButton);
this.Controls.Add(this.ParamsButton);
this.Controls.Add(this.CodesButton);
this.Controls.Add(this.EventLabel);
this.Controls.Add(this.EventTextBox);
this.Controls.Add(this.LengthLabel);
this.Controls.Add(this.LengthTextBox);
this.Controls.Add(this.TimeLabel);
this.Controls.Add(this.TimeTextBox);
this.Controls.Add(this.SourceLabel);
this.Controls.Add(this.SourceTextBox);
this.Controls.Add(this.TypeLabel);
this.Controls.Add(this.TypeTextBox);
this.Controls.Add(this.DataLabel);
this.Controls.Add(this.DataTextBox);
this.Controls.Add(this.CloseButton);
this.Controls.Add(this.AboutButton);
this.Name = "ReaderForm";
this.Text = "CS_ScanSample2";
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.ReaderForm_KeyUp);
this.Load += new System.EventHandler(this.ReaderForm_Load);
this.ResumeLayout(false);
}
#endregion
private Symbol.Barcode.Reader MyReader = null;
private Symbol.Barcode.ReaderData MyReaderData = null;
private System.EventHandler MyReadNotifyHandler = null;
private System.EventHandler MyStatusNotifyHandler = null;
private System.EventHandler MyActivatedEventHandler = null;
private System.EventHandler MyDeactivatedEventHandler = null;
private object[] MyReadParamsList = null;
private int CurrentReadParamIndex = 0;
/// <summary>
/// This function scales down the given Form & its child controls in order to
/// make them completely viewable, based on the screen width & height.
/// </summary>
public static void ScaleDown(System.Windows.Forms.Form frm)
{
int scrWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
int scrHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
if (scrWidth < frm.Width)
foreach (System.Windows.Forms.Control cntrl in frm.Controls)
{
cntrl.Width = ((cntrl.Width) * (scrWidth)) / (frm.Width);
cntrl.Left = ((cntrl.Left) * (scrWidth)) / (frm.Width);
}
if (scrHeight < frm.Height)
foreach (System.Windows.Forms.Control cntrl in frm.Controls)
{
cntrl.Height = ((cntrl.Height) * (scrHeight)) / (frm.Height);
cntrl.Top = ((cntrl.Top) * (scrHeight)) / (frm.Height);
}
}
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ReaderForm rf = new ReaderForm();
ScaleDown(rf);
Application.Run(rf);
}
/// <summary>
/// Occurs before the form is displayed for the first time.
/// </summary>
private void ReaderForm_Load(object sender, System.EventArgs e)
{
// Initialize the Reader
if ( this.InitReader() )
{
// Start a read on the reader
this.StartStatus();
this.StartRead();
}
else
{
// If not, close this form
this.Close();
return;
}
// Add MainMenu if Pocket PC
if(Symbol.Win32.PlatformType == "PocketPC")
{
this.Menu = new MainMenu();
}
}
/// <summary>
/// Initialize the reader.
/// </summary>
private bool InitReader()
{
// If reader is already present then fail initialize
if ( this.MyReader != null )
{
return false;
}
try
{
// Get selected device from user
Symbol.Generic.Device MyDevice =
Symbol.StandardForms.SelectDevice.Select(
Symbol.Barcode.Device.Title,
Symbol.Barcode.Device.AvailableDevices);
if ( MyDevice == null )
{
MessageBox.Show("No Device Selected","SelectDevice");
return false;
}
// Create the reader, based on selected device
this.MyReader = new Symbol.Barcode.Reader(MyDevice);
// Create reader data
this.MyReaderData = new Symbol.Barcode.ReaderData(
Symbol.Barcode.ReaderDataTypes.Text,
Symbol.Barcode.ReaderDataLengths.MaximumLabel);
// Enable the Reader
this.MyReader.Actions.Enable();
// Initialize Reader parameters
this.InitReadParams();
// create event handlers
this.MyReadNotifyHandler = new EventHandler(MyReader_ReadNotify);
this.MyStatusNotifyHandler = new EventHandler(MyReader_StatusNotify);
MyActivatedEventHandler = new EventHandler(ReaderForm_Activated);
MyDeactivatedEventHandler = new EventHandler(ReaderForm_Deactivate);
this.Activated += MyActivatedEventHandler;
this.Deactivate += MyDeactivatedEventHandler;
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
MessageBox.Show("InitReader\n"+"Invalid Operation\n"+ex.Message);
return false;
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("InitReader\n"+"Operation Failure"+ex.Message);
return false;
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("InitReader\n"+"Unimplemented Function"+ex.Message);
return false;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -