public static PictureBox CreatePicBox(TxTDrawStyle style, string value , string name, decimal left, decimal top, decimal width , decimal height , Font font, int alignmentIndex , string fieldName) { PictureBox addPic = new PictureBox(); addPic.Name = name; //字体的磅值=字体的实际高度(厘米)×1.073÷0.035 addPic.BorderStyle = BorderStyle.FixedSingle; // moveEnt.SetControlMove(addPic); addPic.Width = (int)MMTOPels(width); addPic.Height = (int)MMTOPels(height); addPic.Left = (int)MMTOPels(left); addPic.Top = (int)MMTOPels(top); DataEnt data = new DataEnt(style, value, fieldName, font, alignmentIndex); addPic.Tag = data; return(addPic); }
public static PictureBox CreatePicBoxPil(TxTDrawStyle style, string value , string name, decimal left, decimal top, decimal width , decimal height , Font font, int alignmentIndex , string fieldName) { PictureBox addPic = new PictureBox(); addPic.Name = name; addPic.BorderStyle = BorderStyle.FixedSingle; //moveEnt.SetControlMove(addPic); addPic.Width = (int)width; addPic.Height = (int)height; addPic.Left = (int)left; addPic.Top = (int)top; DataEnt data = new DataEnt(style, value, fieldName, font, alignmentIndex); addPic.Tag = data; return(addPic); }
public DataEnt(TxTDrawStyle style, string value, string fieldName //, string fontName, int fontValue, int fontStyle) , Font font, int alignmentIndex) { _Style = style; _Value = value; _FieldName = fieldName; //_FontName = fontName; //_FontValue = fontValue; //_FontStyle = (TxTFontStyle)fontStyle; _Font = font; _Alignment = (AlignmentStyle)alignmentIndex; }
/// <summary> /// 根据模版及数据信息绘制相应的图片 /// </summary> /// <param name="g"></param> /// <param name="dataObject"></param> /// <param name="formatTable"></param> /// <returns></returns> private Image DrawPrintPic(Graphics g, Object dataObject, DataTable formatTable) { if (dataObject == null || formatTable == null) { return(null); } //DataRow dataRow = null; //if (dataObject is DataRow) // dataRow = (DataRow)dataObject; BarCode128PC barCode = null; foreach (DataRow oneRow in formatTable.Rows) { TxTDrawStyle drawStyle = (TxTDrawStyle)(Convert.ToInt32(oneRow["CONTROLSTYLE"])); switch (drawStyle) { case TxTDrawStyle.BACKGROUND: float width = PubOperator.ToFloat(oneRow["ENDX"]) - PubOperator.ToFloat(oneRow["BEGINX"]); float height = PubOperator.ToFloat(oneRow["ENDY"]) - PubOperator.ToFloat(oneRow["BEGINY"]); barCode = new BarCode128PC(g, width, height, g == null ? 1F : PubOperator.PelsValue); break; case TxTDrawStyle.TXT: Font font = new Font(oneRow["FONTNAME"].ToString() , PubOperator.ToFloat(oneRow["FONTVALUE"]) , (FontStyle)PubOperator.ToInt(oneRow["FONTSTYLE"])); float beginX = 0; string valueStr = ReturnValue(dataObject, oneRow); SizeF stringSize = barCode.MainGraphics.MeasureString(valueStr, font); switch ((AlignmentStyle)PubOperator.ToInt(oneRow["ALIGNMENT"])) { case AlignmentStyle.Right: beginX = PubOperator.ToFloat(oneRow["IMAGEWIDTH"]) - stringSize.Width; break; case AlignmentStyle.Middle: beginX = PubOperator.ToFloat(oneRow["IMAGEWIDTH"]) / 2 - stringSize.Width / 2 - 1; break; default: beginX = 0; break; } if (beginX < 0) { beginX = 0; } string s = oneRow["BEGINX"].ToString(); barCode.DrawText(valueStr, font, PubOperator.ToFloat(oneRow["BEGINX"]) + beginX, PubOperator.ToFloat(oneRow["BEGINY"]), false); break; case TxTDrawStyle.LINE: barCode.DrawLine(PubOperator.ToFloat(oneRow["CONTROLVALUE"]) / 10 * PubOperator.PelsValue , PubOperator.ToFloat(oneRow["BEGINX"]), PubOperator.ToFloat(oneRow["BEGINY"]) , PubOperator.ToFloat(oneRow["ENDX"]) - PubOperator.ToFloat(oneRow["BEGINX"]) < 10 ? PubOperator.ToFloat(oneRow["BEGINX"]) : PubOperator.ToFloat(oneRow["ENDX"]) , PubOperator.ToFloat(oneRow["ENDY"]) - PubOperator.ToFloat(oneRow["BEGINY"]) < 10 ? PubOperator.ToFloat(oneRow["BEGINY"]) : PubOperator.ToFloat(oneRow["ENDY"]), false); break; case TxTDrawStyle.BARCODE: barCode.DrawBarcode( ReturnValue(dataObject, oneRow) , PubOperator.ToFloat(oneRow["IMAGEHEIGHT"]) , PubOperator.ToFloat(oneRow["BEGINX"]), PubOperator.ToFloat(oneRow["BEGINY"]), false, false); break; case TxTDrawStyle.IMAGE: Bitmap bm = null; using (MemoryStream mem = new MemoryStream(Convert.FromBase64String(oneRow["CONTROLVALUE"].ToString()))) { bm = Bitmap.FromStream(mem) as Bitmap; } barCode.DrawImage(PubOperator.ToFloat(oneRow["BEGINX"]), PubOperator.ToFloat(oneRow["BEGINY"]), bm); break; default: break; } } return(barCode.Pictrue); }