private void DrawContext(PaintEventArgs e, BedInfo _bed) { e.Graphics.SmoothingMode = SmoothingMode.HighQuality; Font font = new Font(Font.FontFamily, 10.5f, FontStyle.Bold); SizeF fontsize = e.Graphics.MeasureString(_bed.BedNo, font); if (_bed.IsUsed == false) //未使用状态, 在中间画标题 { //重新计算标题栏的位置 _rectBed = new Rectangle((int)(_rectTitle.Width - 40) / 2, 1, 40, _rectTitle.Height - 2); e.Graphics.DrawString(_bed.BedNo, font, Brushes.Black, _rectBed.Left + (40 - fontsize.Width) / 2, _rectBed.Top + (_rectBed.Height - fontsize.Height) / 2 + 1); return; } _rectBed = new Rectangle(1, 1, 30 + 26, _rectTitle.Height - 2); //包床标志时,需要绘制包床背景 if (_bed.Group) { DrawRectangleBackGroup(e.Graphics, _rectBed, Color.Lime, Color.Green, Color.DarkGreen, 0); } e.Graphics.DrawString(_bed.BedNo, font, Brushes.Black, _rectBed.Left + (_rectBed.Width - fontsize.Width + 20) / 2, _rectBed.Top + (_rectBed.Height - fontsize.Height) / 2 + 1); font = new Font(Font.FontFamily, 10f, FontStyle.Bold); //显示男女图标 //ResourceManager rm = new ResourceManager(typeof(BedCardControl)); Rectangle rect = new Rectangle(_rectTitle.Left + 2, _rectTitle.Top + (_rectTitle.Height - 20) / 2 + 1, 24, 20); if (_bed.Sex == "男") { e.Graphics.DrawImage(Resources.PatientMale, rect, new Rectangle(0, 0, Resources.PatientMale.Width, Resources.PatientMale.Height), GraphicsUnit.Pixel); } else if (_bed.Sex == "女") { e.Graphics.DrawImage(Resources.PatientFemale, rect, new Rectangle(0, 0, Resources.PatientFemale.Width, Resources.PatientFemale.Height), GraphicsUnit.Pixel); } //显示姓名和年龄 String sText = _bed.PatientName + " " + _bed.Age; if (sText.Length > 0) { fontsize = e.Graphics.MeasureString(sText, Font); e.Graphics.DrawString(sText, font, (_bed.Step >= 8) ? Brushes.Red : (_bed.Step == 6) ? Brushes.DodgerBlue : Brushes.Black, new Rectangle(_rectBed.Left + _rectBed.Width + 3, _rectBed.Top + (_rectBed.Height - (int)fontsize.Height) / 2, _rectTitle.Width - _rectBed.Width - 6, (int)fontsize.Height)); e.Graphics.DrawLine(new Pen(_BorderColor), _rectBed.Width, _rectTitle.Top, _rectBed.Width, _rectTitle.Height); } //画图标 float _imgWidth = 20; float _imgHeight = 20; int _imgX = _rectContext.Width - 25; int _imgY = _rectContext.Top + 5; _rectNurse = new Rectangle(_imgX + 3, _imgY + 3, (int)_imgWidth - 6, (int)_imgHeight - 6); _imgY = _imgY + (int)_imgHeight; _rectHeadPage = new Rectangle(_imgX, _imgY, (int)_imgWidth, (int)_imgHeight); _imgY = _imgY + (int)_imgHeight; _rectTemperature = new Rectangle(_imgX, _imgY, (int)_imgWidth, (int)_imgHeight); _imgY = _imgY + (int)_imgHeight; _rectAdvice = new Rectangle(_imgX, _imgY, (int)_imgWidth, (int)_imgHeight); _imgY = _imgY + (int)_imgHeight; _rectApply = new Rectangle(_imgX, _imgY, (int)_imgWidth, (int)_imgHeight); //护理级别 //DrawNurse(e, _bed); //显示卡片内容 int lastfRowHeight = _rectContext.Top + 2; for (int i = 0; i < BedContextFields.Count; i++) { string fname = BedContextFields[i].FieldName + ":"; string fvalue = Tools.ToString(_bed.GetType().GetProperty(BedContextFields[i].DataPropertyName).GetValue(_bed, null)); //标题的宽度 int iContextLeft = (int)(e.Graphics.MeasureString(fname, BedContextFields[i].fieldFontHead).Width) + 4; //内容的宽度 int iContextWidth = _rectContext.Width - iContextLeft - 10; int iRowTop = lastfRowHeight; if (i > 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 = ((int)(_fontsize.Width / iContextWidth) + 1) * _fontsize.Height; iRowTop = lastfRowHeight + (int)_frowheight; } lastfRowHeight = iRowTop; //如果本行内容超过一行,画的高度变成内容的高度 SizeF _fontsizeC = e.Graphics.MeasureString(fvalue, BedContextFields[i].fieldFontContext); float _frowheightC = ((int)(_fontsizeC.Width / iContextWidth) + 1) * _fontsizeC.Height; int _fRowHeight = (int)_frowheightC; e.Graphics.DrawString(fname, BedContextFields[i].fieldFontHead, BedContextFields[i].fontBrushHead, 3, 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(iContextLeft, iRowTop, iContextWidth, _fRowHeight)); } else { e.Graphics.DrawString(fvalue, BedContextFields[i].fieldFontContext, BedContextFields[i].fontBrushContext, new Rectangle(iContextLeft, iRowTop, iContextWidth, _fRowHeight)); } } }
/// <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); } } }