/// <summary> /// The static Select method is the recommended way to create the SelectDevice /// dialog. /// </summary> /// <remarks> /// This method will display the SelectDevice dialog and block until a /// selection has been made. /// </remarks> /// <param name="Title">A string that will be displayed as the title to the /// SelectDevice dialog.</param> /// <param name="AvailableDevices">An array of available Symbol.Device objects. /// </param> /// <param name="SelectIndex">The index of the initially selected device /// object.</param> /// <returns>The selected device object.</returns> public static Symbol.Barcode2.Device Select(string Title, Symbol.Barcode2.Device[] AvailableDevices, int SelectIndex) { OurAvailableDevices = AvailableDevices; if (OurAvailableDevices.Length == 0) { return(null); } if (OurAvailableDevices.Length == 1) { return(OurAvailableDevices[0]); } OurTitle = Title; DefaultIndex = SelectIndex; int nSelection = new SelectDevice().Selection; if (nSelection < 0) { return(null); } return(OurAvailableDevices[nSelection]); }
/// <summary> /// This function scales the given Form and its child controls in order to /// make them completely viewable, based on the screen width and height. /// </summary> private static void Scale(SelectDevice frm) { int PSWAW = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width; // The width of the working area (in pixels). int PSWAH = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height; // The height of the working area (in pixels). // The entire screen has been taken in to account below // in order to decide the half (S)VGA settings etc. if (!((Screen.PrimaryScreen.Bounds.Width <= (1.5) * (Screen.PrimaryScreen.Bounds.Height)) && (Screen.PrimaryScreen.Bounds.Height <= (1.5) * (Screen.PrimaryScreen.Bounds.Width)))) { if ((Screen.PrimaryScreen.Bounds.Width) > (Screen.PrimaryScreen.Bounds.Height)) { PSWAW = (int)((1.33) * PSWAH); // If the width/height ratio goes beyond 1.5, // the (longer) effective width is made shorter. } } float dpiX = GetDPIX(); // Get the horizontal DPI value. if (frm.bInitialScale == true) // If an initial scale (from scratch) { if (Symbol.Win32.PlatformType.IndexOf("PocketPC") != -1) // If the platform is either Pocket PC or Windows Mobile { frm.Width = PSWAW; // Set the form width. However this setting // would be the ultimate one for Pocket PC (& Windows Mobile)devices. // Just for the sake of consistency, it's explicitely specified here. } else { frm.Width = (int)((frm.Width) * (PSWAW)) / (frm.resWidthReference); // Set the form width for others (Windows CE devices). } } if ((frm.Width <= maxLength * dpiX) || frm.bSkipMaxLen == true) // The calculation of the width & left values for each control // without taking the maximum length restriction into consideration. { foreach (System.Windows.Forms.Control cntrl in frm.Controls) { cntrl.Width = ((cntrl.Width) * (frm.Width)) / (frm.resWidthReference); cntrl.Left = ((cntrl.Left) * (frm.Width)) / (frm.resWidthReference); if (cntrl is System.Windows.Forms.TabControl) { foreach (System.Windows.Forms.TabPage tabPg in cntrl.Controls) { foreach (System.Windows.Forms.Control cntrl2 in tabPg.Controls) { cntrl2.Width = (((cntrl2.Width) * (frm.Width)) / (frm.resWidthReference)); cntrl2.Left = (((cntrl2.Left) * (frm.Width)) / (frm.resWidthReference)); } } } } } else { // The calculation of the width & left values for each control // with the maximum length restriction taken into consideration. foreach (System.Windows.Forms.Control cntrl in frm.Controls) { cntrl.Width = (int)(((cntrl.Width) * (PSWAW)*(maxLength * dpiX)) / (frm.resWidthReference * (frm.Width))); cntrl.Left = (int)(((cntrl.Left) * (PSWAW)*(maxLength * dpiX)) / (frm.resWidthReference * (frm.Width))); if (cntrl is System.Windows.Forms.TabControl) { foreach (System.Windows.Forms.TabPage tabPg in cntrl.Controls) { foreach (System.Windows.Forms.Control cntrl2 in tabPg.Controls) { cntrl2.Width = (int)(((cntrl2.Width) * (PSWAW)*(maxLength * dpiX)) / (frm.resWidthReference * (frm.Width))); cntrl2.Left = (int)(((cntrl2.Left) * (PSWAW)*(maxLength * dpiX)) / (frm.resWidthReference * (frm.Width))); } } } } frm.Width = (int)((frm.Width) * (maxLength * dpiX)) / (frm.Width); } frm.resWidthReference = frm.Width; // Set the reference width to the new value. // A similar calculation is performed below for the height & top values for each control ... if (!((Screen.PrimaryScreen.Bounds.Width <= (1.5) * (Screen.PrimaryScreen.Bounds.Height)) && (Screen.PrimaryScreen.Bounds.Height <= (1.5) * (Screen.PrimaryScreen.Bounds.Width)))) { if ((Screen.PrimaryScreen.Bounds.Height) > (Screen.PrimaryScreen.Bounds.Width)) { PSWAH = (int)((1.33) * PSWAW); } } float dpiY = GetDPIY(); if (frm.bInitialScale == true) { if (Symbol.Win32.PlatformType.IndexOf("PocketPC") != -1) { frm.Height = PSWAH; } else { frm.Height = (int)((frm.Height) * (PSWAH)) / (frm.resHeightReference); } } if ((frm.Height <= maxLength * dpiY) || frm.bSkipMaxLen == true) { foreach (System.Windows.Forms.Control cntrl in frm.Controls) { cntrl.Height = ((cntrl.Height) * (frm.Height)) / (frm.resHeightReference); cntrl.Top = ((cntrl.Top) * (frm.Height)) / (frm.resHeightReference); if (cntrl is System.Windows.Forms.TabControl) { foreach (System.Windows.Forms.TabPage tabPg in cntrl.Controls) { foreach (System.Windows.Forms.Control cntrl2 in tabPg.Controls) { cntrl2.Height = ((cntrl2.Height) * (frm.Height)) / (frm.resHeightReference); cntrl2.Top = ((cntrl2.Top) * (frm.Height)) / (frm.resHeightReference); } } } } } else { foreach (System.Windows.Forms.Control cntrl in frm.Controls) { cntrl.Height = (int)(((cntrl.Height) * (PSWAH)*(maxLength * dpiY)) / (frm.resHeightReference * (frm.Height))); cntrl.Top = (int)(((cntrl.Top) * (PSWAH)*(maxLength * dpiY)) / (frm.resHeightReference * (frm.Height))); if (cntrl is System.Windows.Forms.TabControl) { foreach (System.Windows.Forms.TabPage tabPg in cntrl.Controls) { foreach (System.Windows.Forms.Control cntrl2 in tabPg.Controls) { cntrl2.Height = (int)(((cntrl2.Height) * (PSWAH)*(maxLength * dpiY)) / (frm.resHeightReference * (frm.Height))); cntrl2.Top = (int)(((cntrl2.Top) * (PSWAH)*(maxLength * dpiY)) / (frm.resHeightReference * (frm.Height))); } } } } frm.Height = (int)((frm.Height) * (maxLength * dpiY)) / (frm.Height); } frm.resHeightReference = frm.Height; if (frm.bInitialScale == true) { frm.bInitialScale = false; // If this was the initial scaling (from scratch), it's now complete. } if (frm.bSkipMaxLen == true) { frm.bSkipMaxLen = false; // No need to consider the maximum length restriction now. } }
/// <summary> /// Initialize the Barcode2 object. /// </summary> public bool InitBarcode() { // If the Barcode2 object is already initialized then fail the initialization. if (myBarcode2 != null) { return(false); } else // Else initialize the reader. { try { // Get the device selected by the user. Device MyDevice = SelectDevice.Select("Barcode", Symbol.Barcode2.Devices.SupportedDevices); if (MyDevice == null) { MessageBox.Show(Resources.GetString("NoDeviceSelected"), Resources.GetString("SelectDevice")); return(false); } // Create the reader, based on selected device. myBarcode2 = new Barcode2(MyDevice); // In this sample, we are setting the aim type to trigger. switch (myBarcode2.Config.Reader.ReaderType) { case READER_TYPES.READER_TYPE_IMAGER: myBarcode2.Config.Reader.ReaderSpecific.ImagerSpecific.AimType = AIM_TYPE.AIM_TYPE_TRIGGER; break; case READER_TYPES.READER_TYPE_LASER: myBarcode2.Config.Reader.ReaderSpecific.LaserSpecific.AimType = AIM_TYPE.AIM_TYPE_TRIGGER; break; } myBarcode2.Config.Reader.Set(); } catch (OperationFailureException ex) { MessageBox.Show(Resources.GetString("InitBarcode") + "\n" + Resources.GetString("OperationFailure") + "\n" + ex.Message + "\n" + Resources.GetString("Result") + " = " + (Results)((uint)ex.Result) ); return(false); } catch (InvalidRequestException ex) { MessageBox.Show(Resources.GetString("InitBarcode") + "\n" + Resources.GetString("InvalidRequest") + "\n" + ex.Message); return(false); } catch (InvalidIndexerException ex) { MessageBox.Show(Resources.GetString("InitBarcode") + "\n" + Resources.GetString("InvalidIndexer") + "\n" + ex.Message); return(false); }; return(true); } }