//--------------------------------------------------------------------
// FILENAME: ControlForm.cs
//
// Copyright(c) 2005 Symbol Technologies Inc. All rights reserved.
//
// DESCRIPTION:
//
// NOTES:
//
//
//--------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
namespace CS_DisplaySample1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class ControlForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TrackBar BacklightLeveltrackBar;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button AboutButton;
private System.Windows.Forms.Button ExitButton;
private System.Windows.Forms.TrackBar ContrastLeveltrackBar;
private System.Windows.Forms.Label Contrastlabel;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.CheckBox BacklightCheckBox;
private Symbol.Display.Controller MyDisplayController=
null;
public ControlForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.AboutButton.Focus();
}
/// <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.BacklightLeveltrackBar =
new System.Windows.Forms.TrackBar();
this.label1 =
new System.Windows.Forms.Label();
this.Contrastlabel =
new System.Windows.Forms.Label();
this.ContrastLeveltrackBar =
new System.Windows.Forms.TrackBar();
this.AboutButton =
new System.Windows.Forms.Button();
this.ExitButton =
new System.Windows.Forms.Button();
this.label2 =
new System.Windows.Forms.Label();
this.label3 =
new System.Windows.Forms.Label();
this.label4 =
new System.Windows.Forms.Label();
this.label5 =
new System.Windows.Forms.Label();
this.BacklightCheckBox =
new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// BacklightLeveltrackBar
//
this.BacklightLeveltrackBar.LargeChange =
1;
this.BacklightLeveltrackBar.Location =
new System.Drawing.Point(
16,
104);
this.BacklightLeveltrackBar.Name =
"BacklightLeveltrackBar";
this.BacklightLeveltrackBar.Size =
new System.Drawing.Size(
152,
45);
this.BacklightLeveltrackBar.TabIndex =
3;
this.BacklightLeveltrackBar.ValueChanged +=
new System.EventHandler(
this.BacklightLeveltrackBar_ValueChanged);
//
// label1
//
this.label1.Location =
new System.Drawing.Point(
16,
80);
this.label1.Name =
"label1";
this.label1.Size =
new System.Drawing.Size(
152,
16);
this.label1.Text =
"Backlight Levels";
//
// Contrastlabel
//
this.Contrastlabel.Location =
new System.Drawing.Point(
16,
160);
this.Contrastlabel.Name =
"Contrastlabel";
this.Contrastlabel.Size =
new System.Drawing.Size(
152,
16);
this.Contrastlabel.Text =
"Contrast Levels";
//
// ContrastLeveltrackBar
//
this.ContrastLeveltrackBar.LargeChange =
1;
this.ContrastLeveltrackBar.Location =
new System.Drawing.Point(
16,
184);
this.ContrastLeveltrackBar.Name =
"ContrastLeveltrackBar";
this.ContrastLeveltrackBar.Size =
new System.Drawing.Size(
160,
45);
this.ContrastLeveltrackBar.TabIndex =
4;
this.ContrastLeveltrackBar.ValueChanged +=
new System.EventHandler(
this.ContrastLeveltrackBar_ValueChanged);
//
// AboutButton
//
this.AboutButton.Location =
new System.Drawing.Point(
8,
240);
this.AboutButton.Name =
"AboutButton";
this.AboutButton.Size =
new System.Drawing.Size(
88,
24);
this.AboutButton.TabIndex =
0;
this.AboutButton.Text =
"About";
this.AboutButton.Click +=
new System.EventHandler(
this.AboutButton_Click);
this.AboutButton.KeyDown +=
new System.Windows.Forms.KeyEventHandler(
this.AboutButton_KeyDown);
//
// ExitButton
//
this.ExitButton.Location =
new System.Drawing.Point(
160,
240);
this.ExitButton.Name =
"ExitButton";
this.ExitButton.Size =
new System.Drawing.Size(
72,
24);
this.ExitButton.TabIndex =
1;
this.ExitButton.Text =
"Exit";
this.ExitButton.Click +=
new System.EventHandler(
this.ExitButton_Click);
this.ExitButton.KeyDown +=
new System.Windows.Forms.KeyEventHandler(
this.ExitButton_KeyDown);
//
// label2
//
this.label2.Location =
new System.Drawing.Point(
24,
128);
this.label2.Name =
"label2";
this.label2.Size =
new System.Drawing.Size(
24,
24);
//
// label3
//
this.label3.Location =
new System.Drawing.Point(
152,
128);
this.label3.Name =
"label3";
this.label3.Size =
new System.Drawing.Size(
24,
24);
//
// label4
//
this.label4.Location =
new System.Drawing.Point(
24,
208);
this.label4.Name =
"label4";
this.label4.Size =
new System.Drawing.Size(
24,
24);
//
// label5
//
this.label5.Location =
new System.Drawing.Point(
152,
208);
this.label5.Name =
"label5";
this.label5.Size =
new System.Drawing.Size(
24,
24);
//
// BacklightCheckBox
//
this.BacklightCheckBox.Location =
new System.Drawing.Point(
24,
40);
this.BacklightCheckBox.Name =
"BacklightCheckBox";
this.BacklightCheckBox.Size =
new System.Drawing.Size(
168,
20);
this.BacklightCheckBox.TabIndex =
2;
this.BacklightCheckBox.Text =
"Backlight (checked = ON)";
this.BacklightCheckBox.CheckStateChanged +=
new System.EventHandler(
this.BacklightCheckBox_CheckStateChanged);
this.BacklightCheckBox.KeyDown +=
new System.Windows.Forms.KeyEventHandler(
this.BacklightCheckBox_KeyDown);
//
// ControlForm
//
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.label1);
this.Controls.Add(
this.label2);
this.Controls.Add(
this.label3);
this.Controls.Add(
this.label4);
this.Controls.Add(
this.label5);
this.Controls.Add(
this.Contrastlabel);
this.Controls.Add(
this.BacklightCheckBox);
this.Controls.Add(
this.BacklightLeveltrackBar);
this.Controls.Add(
this.ContrastLeveltrackBar);
this.Controls.Add(
this.AboutButton);
this.Controls.Add(
this.ExitButton);
this.Name =
"ControlForm";
this.Text =
"CS_DisplaySample1";
this.KeyUp +=
new System.Windows.Forms.KeyEventHandler(
this.ControlForm_KeyUp);
this.Load +=
new System.EventHandler(
this.ControlForm_Load);
this.ResumeLayout(
false);
}
#endregion
/// <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>
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()
{
ControlForm cf =
new ControlForm();
ScaleDown(cf);
Application.Run(cf);
}
private void ControlForm_Load(
object sender, System.EventArgs e)
{
//Select a device from listing
Symbol.Display.Device MyDevice=
(Symbol.Display.Device)Symbol.StandardForms.SelectDevice.Select(
Symbol.Display.Controller.Title,
Symbol.Display.Device.AvailableDevices);
if(MyDevice ==
null)
{
MessageBox.Show("No Device Selected",
"SelectDevice");
//close the form
this.Close();
return;
}
//Check the device type
switch (MyDevice.DisplayType)
{
// if device is standard device
case Symbol.Display.DisplayType.StandardDisplay:
MyDisplayController =
new Symbol.Display.StandardDisplay(MyDevice);
break;
//if device is simulated device
case Symbol.Display.DisplayType.SimulatedDisplay:
MyDisplayController =
new Symbol.Display.SimulatedDisplay(MyDevice);
break;
default :
throw new Symbol.Exceptions.InvalidDataTypeException(
"Unknown Device Type");
}
//add a event handler to handle event change
this.MyDisplayController.ChangeNotify+=
new EventHandler(MyDisplayController_ChangeNotify);
//if backlightIntensitylevel is supported assign the max and min value to intensity
if (
this.MyDisplayController.BacklightIntensityLevels >
0 )
{
this.BacklightLeveltrackBar.Minimum=
0;
this.BacklightLeveltrackBar.Maximum=(
int)
this.MyDisplayController.BacklightIntensityLevels-
1;
this.BacklightLeveltrackBar.Value = (
int)
this.MyDisplayController.BacklightIntensityLevel;
this.BacklightCheckBox.Checked =
this.MyDisplayController.BacklightState==
Symbol.Display.BacklightState.ON;
this.label2.Text=
this.BacklightLeveltrackBar.Minimum.ToString();
this.label3.Text=
this.BacklightLeveltrackBar.Maximum.ToString();
this.BacklightLeveltrackBar.Show();
this.BacklightCheckBox.Show();
this.label2.Show();
this.label3.Show();
}
else
{
this.BacklightLeveltrackBar.Hide();
this.BacklightCheckBox.Hide();
this.label2.Hide();
this.label3.Hide();
}
if (
this.MyDisplayController.ContrastLevels >
0 )
{
this.ContrastLeveltrackBar.Minimum=
0;
this.ContrastLeveltrackBar.Maximum=
this.MyDisplayController.ContrastLevels-
1;
this.ContrastLeveltrackBar.Value=
this.MyDisplayController.ContrastLevel;
this.label4.Text=
this.ContrastLeveltrackBar.Minimum.ToString();
this.label5.Text=
this.ContrastLeveltrackBar.Maximum.ToString();
this.label4.Show();
this.label5.Show();
this.Contrastlabel.Show();
this.ContrastLeveltrackBar.Show();
}
else
{
this.label4.Hide();
this.label5.Hide();
this.Contrastlabel.Hide();
this.ContrastLeveltrackBar.Hide();
}
// Add MainMenu if Pocket PC
if(Symbol.Win32.PlatformType ==
"PocketPC")
{
this.Menu =
new MainMenu();
}
}
private void AboutButton_Click(
object sender, System.EventArgs e)
{
string sVerInfo=
"CS_DisplaySample1 - C# Display Control Sample 1"+
"\r\n"+
"\n"+
"CAPI Version\t"+
this.MyDisplayController.Version.CAPIVersion+
"\r\n" +
"Assembly Version\t"+
this.MyDisplayController.Version.AssemblyVersion;
//Display The about Dialog
Symbol.StandardForms.About.Run(
null,sVerInfo);
this.AboutButton.Focus();
}
private void ExitButton_Click(
object sender, System.EventArgs e)
{
//Release all the resource before exiting
this.MyDisplayController.Dispose ();
//close the form
this.Close();
}
private void AboutButton_KeyDown(
object sender, KeyEventArgs e)
{
// Checks if the key pressed was an enter button (character code 13)
if (e.KeyValue == (
char)
13)
AboutButton_Click(this, e);
}
private void ExitButton_KeyDown(
object sender, KeyEventArgs e)
{
// Checks if the key pressed was an enter button (character code 13)
if (e.KeyValue == (
char)
13)
ExitButton_Click(this, e);
}
private void ControlForm_KeyUp(
object sender, KeyEventArgs e)
{
this.AboutButton.Focus();
}
private void MyDisplayController_ChangeNotify(
object sender, System.EventArgs e)
{
//to Get the next status of display controller
Symbol.Display.DisplayStatus MyStatus=
this.MyDisplayController.GetNextStatus ();
if(MyStatus !=
null)
{
switch(MyStatus.Change)
{
case Symbol.Display.ChangeType.BACKLIGHT:
//Backlight change
if(
this.MyDisplayController.BacklightState==
Symbol.Display.BacklightState.ON )
this.BacklightCheckBox.Checked =
true;
else
this.BacklightCheckBox.Checked =
false;
break;
case Symbol.Display.ChangeType.INTENSITY:
//Intensity change
this.BacklightLeveltrackBar.Value =
this.MyDisplayController.BacklightIntensityLevel;
break;
case Symbol.Display.ChangeType.CONTRAST:
//contrast change
this.ContrastLeveltrackBar.Value =
this.MyDisplayController.ContrastLevel;
break;
}
}
}
private void BacklightLeveltrackBar_ValueChanged(
object sender, System.EventArgs e)
{
this.MyDisplayController.BacklightIntensityLevel=
this.BacklightLeveltrackBar.Value;
}
private void BacklightCheckBox_CheckStateChanged(
object sender, System.EventArgs e)
{
if(
this.BacklightCheckBox.Checked)
this.MyDisplayController.BacklightState=
Symbol.Display.BacklightState.ON;
else
this.MyDisplayController.BacklightState=
Symbol.Display.BacklightState.OFF;
}
private void BacklightCheckBox_KeyDown(
object sender, KeyEventArgs e)
{
// Checks if the key pressed was an enter button (character code 13)
if (e.KeyValue == (
char)
13)
{
this.BacklightCheckBox.Checked = !(
this.BacklightCheckBox.Checked);
BacklightCheckBox_CheckStateChanged(this, e);
}
}
private void ContrastLeveltrackBar_ValueChanged(
object sender, System.EventArgs e)
{
this.MyDisplayController.ContrastLevel=
this.ContrastLeveltrackBar.Value;
}
}
}
转载于:https://www.cnblogs.com/jamesping/articles/2664688.html