/// <summary> /// 加载默认值 /// </summary> private void LoadDisplay() { Task.Run(() => { this.wifiTxt.Text = FormConfigUtil.WifiPath; this.localTxt.Text = FormConfigUtil.LocationPath; this.logTxt.Text = FormConfigUtil.LogPath; this.ipTxt.Text = FormConfigUtil.IpPath; this.countTxt.Text = FormConfigUtil.PrintCount.ToString(); var list = new List <object> { new { key = "默认居中", value = "默认居中" } }; this.localComboBox.DataSource = list; this.localComboBox.ValueMember = "value"; this.localComboBox.DisplayMember = "key"; this.localComboBox.SelectedValue = FormConfigUtil.ImgLocation; this.pageSize = ImageSizeUtil.ConverntPaperSizeName(FormConfigUtil.PageSize); this.landscape = FormConfigUtil.Landscape; this.marginLeft = FormConfigUtil.MarginLeft; this.marginRight = FormConfigUtil.MarginRight; this.marginTop = FormConfigUtil.MarginTop; this.marginBottom = FormConfigUtil.MarginBottom; this.printDocument.DefaultPageSettings.PaperSize = FormConfigUtil.GetPaperSize(printDocument, pageSize); this.printDocument.DefaultPageSettings.Margins.Top = this.marginTop; this.printDocument.DefaultPageSettings.Margins.Left = this.marginLeft; this.printDocument.DefaultPageSettings.Margins.Right = this.marginRight; this.printDocument.DefaultPageSettings.Margins.Bottom = this.marginBottom; this.portTxt.Text = FormConfigUtil.Host; }); }
/// <summary> /// 选择打印机 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void selPrintBtn_Click(object sender, EventArgs e) { var printerName = this.ShowPrintList(); if (!string.IsNullOrEmpty(printerName)) { this.PrintName = printerName; FormConfigUtil.SetConfig(new Dictionary <string, string> { { "printName", this.PrintName } }); } }
/// <summary> /// 设置打印机 /// </summary> private void SetPrint() { //设置打印份数 printDocument.PrinterSettings.Copies = short.Parse(this.countTxt.Text); //启用页边距 printDocument.OriginAtMargins = false; //横向纵向设置 printDocument.DefaultPageSettings.Landscape = FormConfigUtil.Landscape; //尺寸设置 printDocument.DefaultPageSettings.PaperSize = FormConfigUtil.GetPaperSize(printDocument, this.PagerSize); //打印机名称 printDocument.PrinterSettings.PrinterName = this.PrintName; }
private void saveBtn_Click(object sender, EventArgs e) { var wifiPath = this.wifiTxt.Text; var loaclPath = this.localTxt.Text; var logPath = this.logTxt.Text; var ipPath = this.ipTxt.Text; var countPath = this.countTxt.Text; var imgPath = this.localComboBox.SelectedValue.ToString(); var printCount = this.countTxt.Text; var port = this.portTxt.Text; string size = ImageSizeUtil.ConverntPaperSize(this.pageSize); var dic = new Dictionary <string, string> { { "wifiPath", wifiPath }, { "locationPath", loaclPath }, { "logPath", logPath }, { "ipPath", ipPath }, { "imgLocation", imgPath }, { "printCount", printCount }, { "pageSize", size }, { "landscape", this.landscape.ToString() }, { "marginLeft", this.marginLeft.ToString() }, { "marginRight", this.marginRight.ToString() }, { "marginTop", this.marginTop.ToString() }, { "marginBottom", this.marginBottom.ToString() }, { "host", port } }; FormConfigUtil.SetConfig(dic); FormFactory.MainForm.InitForm(); FormFactory.MainForm.ReloadService(x => { if (x) { MessageBox.Show("设置保存成功"); } else { MessageBox.Show("端口已被占用,请重新设置端口"); } }); }