private void button_getFont_Click(object sender, EventArgs e) { FontDialog dlg = new FontDialog(); dlg.ShowColor = false; dlg.Font = Global.BuildFont(this.textBox_fontString.Text); dlg.ShowApply = false; dlg.ShowHelp = true; dlg.AllowVerticalFonts = false; try { if (dlg.ShowDialog(this) != DialogResult.OK) { return; } } catch (Exception ex) { MessageBox.Show(this, ExceptionUtil.GetAutoText(ex)); return; } this.textBox_fontString.Text = FontUtil.GetFontString(dlg.Font); }
// 将内容创建为 XmlDocument public int ToXmlDocument(out XmlDocument dom, out string strError) { strError = ""; dom = new XmlDocument(); dom.LoadXml("<root />"); // <page> XmlElement page = dom.CreateElement("page"); dom.DocumentElement.AppendChild(page); DomUtil.SetAttr(page, "width", this.PageWidth.ToString()); DomUtil.SetAttr(page, "height", this.PageHeight.ToString()); DomUtil.SetAttr(page, "margins", ToString(this.PageMargins)); DomUtil.SetAttr(page, "defaultPrinter", this.DefaultPrinter); #if NO if (this.Landscape == true) { DomUtil.SetAttr(page, "landscape", "yes"); } #endif if (this.RotateDegree != 0) { DomUtil.SetAttr(page, "rotate", this.RotateDegree.ToString()); } // <label> XmlElement label = dom.CreateElement("label"); dom.DocumentElement.AppendChild(label); DomUtil.SetAttr(label, "width", this.LabelWidth.ToString()); DomUtil.SetAttr(label, "height", this.LabelHeight.ToString()); DomUtil.SetAttr(label, "paddings", ToString(this.LabelPaddings)); if (this.IsBarcodeFont == true) { DomUtil.SetAttr(label, "font", Global.GetBarcodeFontString(this.Font)); } else { DomUtil.SetAttr(label, "font", FontUtil.GetFontString(this.Font)); } DomUtil.SetAttr(label, "lineSep", this.LineSep.ToString()); // <lineFormats> if (this.LineFormats.Count > 0) { XmlElement lineFormats = dom.CreateElement("lineFormats"); dom.DocumentElement.AppendChild(lineFormats); foreach (LineFormat format in this.LineFormats) { XmlElement line = dom.CreateElement("line"); lineFormats.AppendChild(line); if (format.Font != null) { if (format.IsBarcodeFont == true) { DomUtil.SetAttr(line, "font", Global.GetBarcodeFontString(format.Font)); } else { DomUtil.SetAttr(line, "font", FontUtil.GetFontString(format.Font)); } } DomUtil.SetAttr(line, "align", format.Align); Debug.Assert(double.IsNaN(format.OffsetX) == false, "OffsetX 不可能为 NaN"); Debug.Assert(double.IsNaN(format.OffsetY) == false, "OffsetY 不可能为 NaN"); if (format.OffsetX != 0 || format.OffsetY != 0) { line.SetAttribute("offset", format.OffsetX + "," + format.OffsetY); } if (double.IsNaN(format.StartX) == false || double.IsNaN(format.StartY) == false) { line.SetAttribute("start", ToString(format.StartX) + "," + ToString(format.StartY)); } if (double.IsNaN(format.Width) == false || double.IsNaN(format.Height) == false) { line.SetAttribute("size", ToString(format.Width) + "," + ToString(format.Height)); } if (string.IsNullOrEmpty(format.ForeColor) == false) { line.SetAttribute("foreColor", format.ForeColor); } if (string.IsNullOrEmpty(format.BackColor) == false) { line.SetAttribute("backColor", format.BackColor); } } } return(0); }