protected override void OnPaint(PaintEventArgs e) { // int left = 0; foreach (DataRow row in tbstyle.Rows) { if ((bool)row["display"] == true) { Rectangle rec = new Rectangle(left, 0, Convert.ToInt16(row["width"]), info.columnHeight); var sf = Conv.AlignToStringFormat(Convert.ToInt16(row["align"])); e.Graphics.DrawString(row["colbyname"].ToString(), this.Font, new SolidBrush(this._Color), rec, sf); e.Graphics.DrawRectangle(Pens.Black, rec); left += Convert.ToInt16(row["width"]); } } // if (_Selected == false) { Pen p = new Pen(Color.Gray); p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; e.Graphics.DrawRectangle(p, 0, 0, this.Width - 1, this.Height - 1); } else { if (_FirstSelected == true) { e.Graphics.DrawRectangle(new Pen(Color.Blue, 2), 1, 1, this.Width - 2, this.Height - 2); } else { e.Graphics.DrawRectangle(Pens.Blue, 0, 0, this.Width - 1, this.Height - 1); } } }
protected override void OnPaint(PaintEventArgs e) { var sf = Conv.AlignToStringFormat(this._align); Rectangle rec = new Rectangle(0, 0, this.Width, this.Height); e.Graphics.DrawString(_context, this.Font, new SolidBrush(this._Color), rec, sf); if (this._BorderLeft == 1) { e.Graphics.DrawLine(Pens.Black, 0, 0, 0, this.Height); } if (this._BorderRight == 1) { e.Graphics.DrawLine(Pens.Black, this.Width - 1, 0, this.Width - 1, this.Height); } if (this._BorderTop == 1) { e.Graphics.DrawLine(Pens.Black, 0, 0, this.Width, 0); } if (this._BorderBottom == 1) { e.Graphics.DrawLine(Pens.Black, 0, this.Height - 1, this.Width - 1, this.Height - 1); } if (_Selected == false) { Pen p = new Pen(Color.Gray); p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; e.Graphics.DrawRectangle(p, 0, 0, this.Width - 1, this.Height - 1); } else { if (_FirstSelected == true) { e.Graphics.DrawRectangle(new Pen(Color.Blue, 2), 1, 1, this.Width - 2, this.Height - 2); } else { e.Graphics.DrawRectangle(Pens.Blue, 0, 0, this.Width - 1, this.Height - 1); } } }
private void Draw(System.Drawing.Graphics g, int pageIndex, bool isFirst, bool isLast) { ReadXml r = new ReadXml(xml); foreach (ReadXml r2 in r.ReadList("PrintObject1")) { int left = Convert.ToInt16(r2.Read("Left")); int top = Convert.ToInt16(r2.Read("Top")); int Width = Convert.ToInt16(r2.Read("Width")); int Height = Convert.ToInt16(r2.Read("Height")); string context = r2.Read("Context"); int Align = Convert.ToInt16(r2.Read("Align")); var sf = Conv.AlignToStringFormat(Align); FontConverter fc = new FontConverter(); var font = (Font)fc.ConvertFromString(r2.Read("Font")); var color = Color.FromArgb(Convert.ToInt32(r2.Read("Color"))); int Area = Convert.ToInt16(r2.Read("Area")); int _BorderLeft = Convert.ToInt16(r2.Read("BorderLeft")); int _BorderRight = Convert.ToInt16(r2.Read("BorderRight")); int _BorderTop = Convert.ToInt16(r2.Read("BorderTop")); int _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom")); Rectangle rec = new Rectangle(left, top, Width, Height); if (Area == 2 && isFirst == false || Area == 4 && isLast == false) { } else { g.DrawString(context, font, new SolidBrush(color), rec, sf); if (_BorderLeft == 1) { g.DrawLine(Pens.Black, left, top, left, top + Height); } if (_BorderRight == 1) { g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height); } if (_BorderTop == 1) { g.DrawLine(Pens.Black, left, top, left + Width, top); } if (_BorderBottom == 1) { g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height); } } } foreach (ReadXml r2 in r.ReadList("PrintObject2")) { int left = Convert.ToInt16(r2.Read("Left")); int top = Convert.ToInt16(r2.Read("Top")); int Width = Convert.ToInt16(r2.Read("Width")); int Height = Convert.ToInt16(r2.Read("Height")); string Field = r2.Read("Field"); string Format = r2.Read("Format"); int Align = Convert.ToInt16(r2.Read("Align")); var sf = Conv.AlignToStringFormat(Align); FontConverter fc = new FontConverter(); var font = (Font)fc.ConvertFromString(r2.Read("Font")); var color = Color.FromArgb(Convert.ToInt32(r2.Read("Color"))); int Area = Convert.ToInt16(r2.Read("Area")); int _BorderLeft = Convert.ToInt16(r2.Read("BorderLeft")); int _BorderRight = Convert.ToInt16(r2.Read("BorderRight")); int _BorderTop = Convert.ToInt16(r2.Read("BorderTop")); int _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom")); Rectangle rec = new Rectangle(left, top, Width, Height); if (Area == 2 && isFirst == false || Area == 4 && isLast == false) { } else { if (tbmain.Rows.Count != 0) { DataRow row = tbmain.Rows[0]; DataColumn col = tbmain.Columns[Field]; string context = ""; if (Format == "") { context = row[Field].ToString(); } else if (Format == "大写金额") { context = Conv.DaXie2(row[Field].ToString()); } else if (Format == "条形码") { Barcode.CreateBarcodeImage(g, rec.X, rec.Y, "C", row[Field].ToString(), 1F, rec.Height); } else if (Format == "二维码") { QRCode code = new QRCode(); Bitmap bit = code.grant_qrcode(row[Field].ToString(), rec.Width, rec.Width); g.DrawImage(bit, rec); } else { if (col.DataType == typeof(decimal)) { context = Conv.ToDecimal(row[Field]).ToString(Format); } else if (col.DataType == typeof(Int16)) { context = Conv.ToInt16(row[Field]).ToString(Format); } else if (col.DataType == typeof(Int32)) { context = Conv.ToInt32(row[Field]).ToString(Format); } else if (col.DataType == typeof(DateTime)) { context = Conv.ToDateTime(row[Field]).ToString(Format); } else { context = row[Field].ToString(); } } if (Format == "条形码") { } else if (Format == "二维码") { } else { g.DrawString(context, font, new SolidBrush(color), rec, sf); } if (_BorderLeft == 1) { g.DrawLine(Pens.Black, left, top, left, top + Height); } if (_BorderRight == 1) { g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height); } if (_BorderTop == 1) { g.DrawLine(Pens.Black, left, top, left + Width, top); } if (_BorderBottom == 1) { g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height); } } } } if (r.Read("PrintObject3") != "") { int flag = 0; foreach (ReadXml r2 in r.ReadList("PrintObject3/Column")) { if (r2.Read("ColName") == "#") { flag = 1; break; } } // if (flag == 0) { IDrawDetail draw = new DrawDetailDefault(); draw.Draw(g, xml, tbdetail, pageIndex); } else { IDrawDetail draw = new DrawDetailJH(); draw.Draw(g, xml, tbdetail, pageIndex); } } foreach (ReadXml r2 in r.ReadList("PrintObject4")) { int left = Convert.ToInt16(r2.Read("Left")); int top = Convert.ToInt16(r2.Read("Top")); int Width = Convert.ToInt16(r2.Read("Width")); int Height = Convert.ToInt16(r2.Read("Height")); var color = Color.FromArgb(Convert.ToInt32(r2.Read("Color"))); int Area = Convert.ToInt16(r2.Read("Area")); if (Area == 2 && isFirst == false || Area == 4 && isLast == false) { } else { g.DrawLine(new Pen(color), left + Width / 2, top, left + Width / 2, top + Height); } } foreach (ReadXml r2 in r.ReadList("PrintObject5")) { int left = Convert.ToInt16(r2.Read("Left")); int top = Convert.ToInt16(r2.Read("Top")); int Width = Convert.ToInt16(r2.Read("Width")); int Height = Convert.ToInt16(r2.Read("Height")); var color = Color.FromArgb(Convert.ToInt32(r2.Read("Color"))); int Area = Convert.ToInt16(r2.Read("Area")); if (Area == 2 && isFirst == false || Area == 4 && isLast == false) { } else { g.DrawLine(new Pen(color), left, top + Height / 2, left + Width, top + Height / 2); } } foreach (ReadXml r2 in r.ReadList("PrintObject6")) { int left = Convert.ToInt16(r2.Read("Left")); int top = Convert.ToInt16(r2.Read("Top")); int Width = Convert.ToInt16(r2.Read("Width")); int Height = Convert.ToInt16(r2.Read("Height")); var img = Conv.StringToImage(r2.Read("Image")); int Area = Convert.ToInt16(r2.Read("Area")); Rectangle rec = new Rectangle(left, top, Width, Height); if (Area == 2 && isFirst == false || Area == 4 && isLast == false) { } else { g.DrawImage(img, rec); } } foreach (ReadXml r2 in r.ReadList("PrintObject7")) { int left = Convert.ToInt16(r2.Read("Left")); int top = Convert.ToInt16(r2.Read("Top")); int Width = Convert.ToInt16(r2.Read("Width")); int Height = Convert.ToInt16(r2.Read("Height")); int Align = Convert.ToInt16(r2.Read("Align")); var sf = Conv.AlignToStringFormat(Align); FontConverter fc = new FontConverter(); var font = (Font)fc.ConvertFromString(r2.Read("Font")); var color = Color.FromArgb(Convert.ToInt32(r2.Read("Color"))); int Area = Convert.ToInt16(r2.Read("Area")); int _BorderLeft = Convert.ToInt16(r2.Read("BorderLeft")); int _BorderRight = Convert.ToInt16(r2.Read("BorderRight")); int _BorderTop = Convert.ToInt16(r2.Read("BorderTop")); int _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom")); Rectangle rec = new Rectangle(left, top, Width, Height); if (Area == 2 && isFirst == false || Area == 4 && isLast == false) { } else { string context = "第N页,共M页".Replace("N", pageIndex.ToString()) .Replace("M", PageCount.ToString()); g.DrawString(context, font, new SolidBrush(color), rec, sf); if (_BorderLeft == 1) { g.DrawLine(Pens.Black, left, top, left, top + Height); } if (_BorderRight == 1) { g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height); } if (_BorderTop == 1) { g.DrawLine(Pens.Black, left, top, left + Width, top); } if (_BorderBottom == 1) { g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height); } } } foreach (ReadXml r2 in r.ReadList("PrintObject8")) { int left = Convert.ToInt16(r2.Read("Left")); int top = Convert.ToInt16(r2.Read("Top")); int Width = Convert.ToInt16(r2.Read("Width")); int Height = Convert.ToInt16(r2.Read("Height")); string format = r2.Read("Format"); int Align = Convert.ToInt16(r2.Read("Align")); var sf = Conv.AlignToStringFormat(Align); FontConverter fc = new FontConverter(); var font = (Font)fc.ConvertFromString(r2.Read("Font")); var color = Color.FromArgb(Convert.ToInt32(r2.Read("Color"))); int Area = Convert.ToInt16(r2.Read("Area")); int _BorderLeft = Convert.ToInt16(r2.Read("BorderLeft")); int _BorderRight = Convert.ToInt16(r2.Read("BorderRight")); int _BorderTop = Convert.ToInt16(r2.Read("BorderTop")); int _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom")); Rectangle rec = new Rectangle(left, top, Width, Height); if (Area == 2 && isFirst == false || Area == 4 && isLast == false) { } else { string context = ""; if (format == "") { context = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } else { context = System.DateTime.Now.ToString(format); } g.DrawString(context, font, new SolidBrush(color), rec, sf); if (_BorderLeft == 1) { g.DrawLine(Pens.Black, left, top, left, top + Height); } if (_BorderRight == 1) { g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height); } if (_BorderTop == 1) { g.DrawLine(Pens.Black, left, top, left + Width, top); } if (_BorderBottom == 1) { g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height); } } } }