private void DrawBackGroup(PaintEventArgs e, BedInfo _bed) { if (SelectedBed != null && SelectedBed.Equals(_bed)) { _BorderColor = Color.FromArgb(194, 126, 48); DrawRectangleBackGroup(e.Graphics, _rectContext, Color.FromArgb(243, 196, 98), Color.FromArgb(255, 228, 138), _BorderColor, 2); } else { _BorderColor = Color.DarkKhaki; DrawRectangleBackGroup(e.Graphics, _rectContext, Color.FromArgb(251, 250, 247), Color.FromArgb(181, 181, 154), _BorderColor, 2); } DrawFilter(_rectTitle, Color.FromArgb(241, 251, 252), Color.FromArgb(213, 221, 234), LinearGradientMode.Vertical, e.Graphics); e.Graphics.DrawRectangle(new Pen(_BorderColor), _rectTitle); e.Graphics.DrawLine(new Pen(_BorderColor), _rectTitle.Width, _rectTitle.Top, _rectTitle.Width, _rectTitle.Height); }
/// <summary> /// 画背景色 /// </summary> /// <param name="e"></param> /// <param name="_bed"></param> private void DrawBackGroup(PaintEventArgs e, BedInfo _bed) { //选中时床卡颜色 if (SelectedBed != null && SelectedBed.Equals(_bed)) { //蓝色:8DEEEE //浅黄:fff7eb //浅黄+1:fdedd5 //浅蓝:e4f1ff DrawRectangleBackGroup(e.Graphics, _rectTitle, ColorTranslator.FromHtml("#fff7eb"), ColorTranslator.FromHtml("#fdedd5"), _BorderColor, 0); DrawRectangleBackGroup(e.Graphics, _rectContext, ColorTranslator.FromHtml("#fff7eb"), ColorTranslator.FromHtml("#fdedd5"), _BorderColor, 2); } // else { DrawRectangleBackGroup(e.Graphics, _rectTitle, Color.White, ColorTranslator.FromHtml("#e4f1ff"), _BorderColor, 0); DrawRectangleBackGroup(e.Graphics, _rectContext, Color.White, ColorTranslator.FromHtml("#e4f1ff"), _BorderColor, 2); } //DrawFilter(_rectTitle, Color.FromArgb(241, 251, 252), Color.FromArgb(213, 221, 234), LinearGradientMode.Vertical, e.Graphics); e.Graphics.DrawRectangle(new Pen(_BorderColor), _rectTitle); //e.Graphics.DrawLine(new Pen(_BorderColor), _rectTitle.Width, _rectTitle.Top, _rectTitle.Width, _rectTitle.Height); }
/// <summary> /// 画内容板 /// </summary> /// <param name="e"></param> /// <param name="_bed"></param> private void DrawContext(PaintEventArgs e, BedInfo _bed) { e.Graphics.SmoothingMode = SmoothingMode.HighQuality; Font font = new Font(Font.FontFamily, 10.5f, FontStyle.Regular); SizeF fontsize = e.Graphics.MeasureString(_bed.BedNo, font); int iLeftMargin = 8; int iTopMargin = 5; int iRow = 0; if (_bed.IsUsed == true) //未使用状态,不需要画 { //显示卡片内容 int lastfRowHeight = _rectContext.Top + iTopMargin + iTopMargin; for (int i = 0; i < BedContextFields.Count; i++) { string fvalue = Tools.ToString(_bed.GetType().GetProperty(BedContextFields[i].DataPropertyName).GetValue(_bed, null)); if (BedContextFields[i].FieldName.Contains("住院号")) { //如果本行内容超过一行,画的高度变成内容的高度 e.Graphics.DrawString(fvalue, BedContextFields[i].fieldFontContext, BedContextFields[i].fontBrushContext, iLeftMargin, lastfRowHeight); } else if (BedContextFields[i].FieldName.Replace(" ", "").Contains("科室")) { //科室内容的宽度 int iDeptWidth = (int)(e.Graphics.MeasureString(fvalue, BedContextFields[i].fieldFontHead).Width) + 4; e.Graphics.DrawString(fvalue, BedContextFields[i].fieldFontContext, BedContextFields[i].fontBrushContext, BedWidth - iDeptWidth, lastfRowHeight); } else { iRow += 1; string fname = BedContextFields[i].FieldName + ":"; //标题的宽度 int iNameWidth = (int)(e.Graphics.MeasureString(fname, BedContextFields[i].fieldFontHead).Width) + 4; //内容的宽度 int iValueWidth = _rectContext.Width - iNameWidth; int iRowTop = lastfRowHeight; if (iRow > 0)//如果上一行内容超过一行,Y向下移 { string _fvalue = Tools.ToString(typeof(BedInfo).GetProperty(BedContextFields[i - 1].DataPropertyName).GetValue(_bed, null)); _fvalue = _fvalue == "" ? "测试" : _fvalue; SizeF _fontsize = e.Graphics.MeasureString(_fvalue, BedContextFields[i - 1].fieldFontContext); //每个值都只占一行,所以这里的计算间隔可暂时忽略 float _frowheight = 1 * _fontsize.Height;//((int)(_fontsize.Width / iValueWidth) + 1) * _fontsize.Height; iRowTop = lastfRowHeight + (int)_frowheight + iTopMargin; } lastfRowHeight = iRowTop; //如果本行内容超过一行,画的高度变成内容的高度 SizeF _fontsizeC = e.Graphics.MeasureString(fvalue, BedContextFields[i].fieldFontContext); int iRowCount = (int)Math.Ceiling(_fontsizeC.Width / iValueWidth); if (iRowCount > 1) { fvalue = fvalue.Substring(0, fvalue.Length / iRowCount - 1) + ".."; } float _frowheightC = iRowCount * _fontsizeC.Height; int _fRowHeight = (int)_frowheightC; e.Graphics.DrawString(fname, BedContextFields[i].fieldFontHead, BedContextFields[i].fontBrushHead, iLeftMargin, iRowTop); if (BedFormatStyleEvent != null) { System.Drawing.Font _font = (Font)BedContextFields[i].fieldFontContext.Clone(); System.Drawing.Brush _brush = (Brush)BedContextFields[i].fontBrushContext.Clone(); BedFormatStyleEvent(_bed, BedContextFields[i].DataPropertyName, ref _font, ref _brush); e.Graphics.DrawString(fvalue, _font, _brush, new Rectangle(iNameWidth, iRowTop, iValueWidth, _fRowHeight)); } else { e.Graphics.DrawString(fvalue, BedContextFields[i].fieldFontContext, BedContextFields[i].fontBrushContext, new Rectangle(iNameWidth, iRowTop, iValueWidth, _fRowHeight)); } } } } else { if (SelectedBed != null && SelectedBed.Equals(_bed)) { int iUnUseHeight = BedHeight - _titleHeight; int iLeft = (BedWidth - Resources.空床图2.Width) / 2; int iTop = (iUnUseHeight - Resources.空床图2.Height) / 2 + _titleHeight; //画空床 Rectangle rect = new Rectangle(iLeft, iTop, Resources.空床图2.Width, Resources.空床图2.Height); e.Graphics.DrawImage(Resources.空床图2, rect, new Rectangle(0, 0, Resources.空床图2.Width, Resources.空床图2.Height), GraphicsUnit.Pixel); } else { int iUnUseHeight = BedHeight - _titleHeight; int iLeft = (BedWidth - Resources.空床图.Width) / 2; int iTop = (iUnUseHeight - Resources.空床图.Height) / 2 + _titleHeight; //画空床 Rectangle rect = new Rectangle(iLeft, iTop, Resources.空床图.Width, Resources.空床图.Height); e.Graphics.DrawImage(Resources.空床图, rect, new Rectangle(0, 0, Resources.空床图.Width, Resources.空床图.Height), GraphicsUnit.Pixel); } } }