public static ValignType StringToValignType(string str, ValignType return_default) { ValignType result; if (str == null) { result = ValignType.Middle; } else { string text = str.Trim().ToLower(); if (text.Equals("top")) { result = ValignType.Top; } else if (text.Equals("middle")) { result = ValignType.Middle; } else if (text.Equals("bottom")) { result = ValignType.Bottom; } else { result = return_default; } } return(result); }
public static bool DrawSpecialValue(Graphics g, string _content, int _left, int _top, int _width, int _height, FontColor _fontcolor, AlignType _align, ValignType _valign, out int _newleft, out int _newtop) { bool result; try { if (g == null) { throw new NullReferenceException(); } if (_content == null) { throw new NullReferenceException(); } if (_fontcolor == null) { throw new NullReferenceException(); } _newleft = _left; _newtop = _top; StringFormat stringFormat = new StringFormat(); if (_align == AlignType.Center) { stringFormat.Alignment = StringAlignment.Center; } else if (_align == AlignType.Left) { stringFormat.Alignment = StringAlignment.Near; } else if (_align == AlignType.Right) { stringFormat.Alignment = StringAlignment.Far; } else { stringFormat.Alignment = StringAlignment.Center; } if (_valign == ValignType.Middle) { stringFormat.LineAlignment = StringAlignment.Center; } else if (_valign == ValignType.Top) { stringFormat.LineAlignment = StringAlignment.Near; } else if (_valign == ValignType.Bottom) { stringFormat.LineAlignment = StringAlignment.Far; } else { stringFormat.LineAlignment = StringAlignment.Center; } string[] array = _content.Split(new char[] { ',' }); if (array == null || array.Length == 1 || array.Length == 2) { g.DrawString(_content, _fontcolor.Font, new SolidBrush(_fontcolor.Color), new RectangleF((float)_left, (float)_top, (float)_width, (float)_height), stringFormat); } else { int num = (int)g.MeasureString(array[0], _fontcolor.Font).Width; Bitmap image = new Bitmap(_width, _height); Graphics graphics = Graphics.FromImage(image); g.DrawString(array[0], _fontcolor.Font, new SolidBrush(_fontcolor.Color), new Point(_left + (_width / 3 - 3), _top + _height / 2), stringFormat); if (array[1].Trim() != "0") { g.DrawString(array[1], _fontcolor.Font, new SolidBrush(_fontcolor.Color), new PointF((float)(_left + _width / 2), (float)_top), stringFormat); g.DrawLine(new Pen(_fontcolor.Color), new Point(_left + _width / 3, _top + _height / 2 - 3), new Point(_left + (_width / 2 + num), _top + _height / 2 - 3)); g.DrawString(array[2], _fontcolor.Font, new SolidBrush(_fontcolor.Color), new PointF((float)(_left + _width / 2), (float)(_top + _height - 5)), stringFormat); } } result = true; } catch (Exception ex) { throw ex; } return(result); }
public static bool DrawString(Graphics g, string _content, int _left, int _top, int _width, int _height, FontColor _fontcolor, AlignType _align, ValignType _valign, out int _newleft, out int _newtop) { bool result; try { if (g == null) { throw new NullReferenceException(); } if (_content == null) { throw new NullReferenceException(); } if (_fontcolor == null) { throw new NullReferenceException(); } _newleft = _left; _newtop = _top; StringFormat stringFormat = new StringFormat(); if (_align == AlignType.Center) { stringFormat.Alignment = StringAlignment.Center; } else if (_align == AlignType.Left) { stringFormat.Alignment = StringAlignment.Near; } else if (_align == AlignType.Right) { stringFormat.Alignment = StringAlignment.Far; } else { stringFormat.Alignment = StringAlignment.Center; } if (_valign == ValignType.Middle) { stringFormat.LineAlignment = StringAlignment.Center; } else if (_valign == ValignType.Top) { stringFormat.LineAlignment = StringAlignment.Near; } else if (_valign == ValignType.Bottom) { stringFormat.LineAlignment = StringAlignment.Far; } else { stringFormat.LineAlignment = StringAlignment.Center; } g.DrawString(_content, _fontcolor.Font, new SolidBrush(_fontcolor.Color), new Rectangle(_left, _top, _width, _height), stringFormat); result = true; } catch (Exception ex) { throw ex; } return(result); }