/// <summary> /// 加载尺寸 /// </summary> /// <param name="strPrinterName">打印机名称</param> private void loadPaperSize(string strPrinterName) { try { PrintDocument printDoc = new PrintDocument(); printDoc.DefaultPageSettings.PrinterSettings.PrinterName = strPrinterName; //保存原先的 ClsKeyOjbect objSelectItem =new ClsKeyOjbect("",null);; if (comboPaperSizes.SelectedItem!=null) { objSelectItem = (ClsKeyOjbect)comboPaperSizes.SelectedItem; } comboPaperSizes.Items.Clear(); foreach (PaperSize item in printDoc.PrinterSettings.PaperSizes) { ClsKeyOjbect myKeyValue = new ClsKeyOjbect(item.PaperName, item); comboPaperSizes.Items.Add(myKeyValue); //判断是否是原先的项目,原先的为空就不用验证了, if ((objSelectItem.strKey!="") && (objSelectItem.strKey == item.PaperName)) { comboPaperSizes.SelectedItem = myKeyValue; } } //如果有相同的纸张定义就选择原先的 if (comboPaperSizes.SelectedItem==null) { //如果没有,就显示第一项 comboPaperSizes.SelectedIndex = 0; } } catch (System.Exception ex) { //ClsErrorFile.WriteLine(ex); } }
/// <summary> /// 加载参数到控件中 /// </summary> private void LoadPageSetting() { if (BarcodePageSettings != null) { BarcodePageSettings.BarcodePaperLayout.Compute(); //如下之纸张项目 //因为这个是在初始化中,所以需要判断原先是否为空 if (comboPaperSizes.Items.Count==0) { ClsKeyOjbect myKeyValue = new ClsKeyOjbect(BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize.PaperName, BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize); comboPaperSizes.Items.Add(myKeyValue); } comboPaperSizes.Text = BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize.PaperName;//设置纸张内容 //如下是布局项目 //如下是布局 UpDownNumberOfLine.Value = BarcodePageSettings.BarcodePaperLayout.NumberOfLine;// 设置行数 UpDownNumberOfColumn.Value = BarcodePageSettings.BarcodePaperLayout.NumberOfColumn;//设置列数 //如下是边距 txtMaginsTop.Text = BarcodePageSettings.BarcodePaperLayout.Top.ToString(); txtMaginsLeft.Text = BarcodePageSettings.BarcodePaperLayout.Left.ToString(); txtMaginsRight.Text = BarcodePageSettings.BarcodePaperLayout.Right.ToString(); txtMaginsBottom.Text = BarcodePageSettings.BarcodePaperLayout.Bottom.ToString(); //如下是模板大小 txtModelWidth.Text = BarcodePageSettings.BarcodePaperLayout.ModelWidth.ToString(); txtModelHeight.Text = BarcodePageSettings.BarcodePaperLayout.ModelHeight.ToString(); chkCustomModelSize.Checked = BarcodePageSettings.BarcodePaperLayout.CustomModelSize; //如下是间距 txtHorizontalInterval.Text = BarcodePageSettings.BarcodePaperLayout.HorizontalInterval.ToString(); txtVerticalInterval.Text = BarcodePageSettings.BarcodePaperLayout.VerticalInterval.ToString(); chkCustomInterval.Checked = BarcodePageSettings.BarcodePaperLayout.CustomDistance; //在预览的下边显示模板大小 lblModelSize.Text = "模板大小: " + BarcodePageSettings.BarcodePaperLayout.ModelWidth.ToString() + " X " + BarcodePageSettings.BarcodePaperLayout.ModelHeight.ToString() + " 毫米"; //如下显示纸张大小 lblPaperSize.Text = "纸张大小: " + BarcodePageSettings.BarcodePaperLayout.PaperWidth.ToString() + " X " +BarcodePageSettings.BarcodePaperLayout.PaperHeight.ToString() + " 毫米"; //设置是否横向 if (BarcodePageSettings.BarcodePaperLayout.LandScape) { radioButton2.Checked = true; radioButton1.Checked = false; } else { radioButton1.Checked = true; radioButton2.Checked = false; } //如下是调用预览 pictureBox1.Refresh(); } }