private bool AutoDetectComPort() { for (int i = 2; i < 8; i++) { string portName = "COM" + i; bool connected = tryToConnectToCOM(portName); DataStream.AppendText("Connecting to " + portName + "\n"); if (connected) { ComboBox1.SelectedIndex = ComboBox1.FindStringExact(portName); return(true); } } return(true); }
/// <summary> /// /// </summary> /// <param name="document"></param> public altPrintDialog(PrintDocument document, int maxPortraitPages, int maxLandscapePages) { dt.Columns.Add("Name"); dt.Columns.Add("Status"); dt.Columns.Add("Type"); dt.Columns.Add("Where"); queryPrinters(ref dt); this.document = document; this.maxPortraitPages = maxPortraitPages; this.maxLandscapePages = maxLandscapePages; string selectedPrinter = this.document.PrinterSettings.PrinterName; // This call is required by the designer. InitializeComponent(); // Add any initialization after the InitializeComponent() call. ComboBox1.DataSource = dt; ComboBox1.DisplayMember = "Name"; Label7.DataBindings.Add("Text", dt, "Status"); Label8.DataBindings.Add("Text", dt, "Type"); Label9.DataBindings.Add("Text", dt, "Where"); ComboBox1.SelectedIndex = ComboBox1.FindStringExact(selectedPrinter); NumericUpDown4.Value = document.DefaultPageSettings.Margins.Left; NumericUpDown5.Value = document.DefaultPageSettings.Margins.Right; NumericUpDown6.Value = document.DefaultPageSettings.Margins.Top; NumericUpDown7.Value = document.DefaultPageSettings.Margins.Bottom; RadioButton4.Checked = this.document.DefaultPageSettings.Landscape; NumericUpDown3.Maximum = RadioButton4.Checked ? maxLandscapePages : maxPortraitPages; NumericUpDown2.Maximum = NumericUpDown3.Maximum; NumericUpDown3.Value = NumericUpDown3.Maximum; NumericUpDown2.Value = 1; this.document.PrinterSettings.FromPage = 1; this.document.PrinterSettings.ToPage = Convert.ToInt32(NumericUpDown3.Value); this.document.PrinterSettings.Collate = false; }