Esempio n. 1
0
        public void Draw(Graphics g, RectangleF rectF)
        {
            using (Brush brush = new SolidBrush(ForeColor))
            {
                if (Image != null)
                {
                    g.DrawImage(Image, rectF);
                }
                else if (_symbolType != MedSymbolType.None)
                {
                    MedSymbol symbol = new MedSymbol(_symbolType);
                    symbol.Size = 8;
                    symbol.Pen  = new Pen(ForeColor);
                    symbol.Draw(g, rectF.X + symbol.Size / 2, rectF.Y + symbol.Size / 2);
                }
                else if (_multiLine)
                {
                    StringFormat sf = new StringFormat();
                    sf.Alignment = StringAlignment.Near;
                    g.DrawString(Text, Font, brush, rectF, sf);
                }
                else
                {
                    switch (TextAlign)
                    {
                    case ContentAlignment.MiddleCenter:
                        g.DrawString(Text, Font, brush, rectF.X + (rectF.Width - g.MeasureString(Text, Font).Width) / 2, rectF.Y + (rectF.Height - g.MeasureString(Text, Font).Height) / 2);
                        break;

                    default:
                        g.DrawString(Text, Font, brush, rectF.X, rectF.Y);
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        public override void DrawGraphics(Graphics g)
        {
            base.DrawGraphics(g);
            using (SolidBrush solidBrush = new SolidBrush(Color.White))
            {
                g.FillRectangle(solidBrush, OriginRect);
            }
            RectangleF rectF = new RectangleF(OriginRect.X + 2, OriginRect.Y + 2, OriginRect.Width - 4, OriginRect.Height - 4);

            if (_vitalSign != null && _legendType == LegengType.Vertical)
            {
                _vitalSign.DrawLegend(g, rectF);
            }
            else
            {
                List <string> aliass = new List <string>();
                int           index  = 0;
                int           idx    = 0;
                if (_legendType == LegengType.Vertical)
                {
                    float offX      = 5;
                    float rowHeight = g.MeasureString("平均动脉压", Font).Height;
                    foreach (string str in _symbolDict.Keys)
                    {
                        idx++;
                        if (string.IsNullOrEmpty(str) || aliass.Contains(str))
                        {
                            continue;
                        }

                        if ((idx - 1) >= _startLegendIndex)
                        {
                            if (rectF.Y + 1 + (index + 1) * rowHeight > rectF.Bottom)
                            {
                                break;
                            }
                            aliass.Add(str);
                            _symbolDict[str].LegengSymbol.Draw(g, rectF.X + offX, rectF.Y + (rowHeight) / 2 + index * rowHeight);
                            using (SolidBrush solidBrush = new SolidBrush(_symbolDict[str].LegengSymbol.Pen.Color))
                            {
                                g.DrawString(_symbolDict[str].LegengName, Font, solidBrush, rectF.X + 3 + _symbolDict[str].LegengSymbol.Size, rectF.Y + 1 + index * rowHeight);
                            }
                            index++;
                        }
                    }
                }
                else if (_legendType == LegengType.Horizontal)
                {
                    //float rowHeight = g.MeasureString("平均动脉压", Font).Height + 2;
                    float     rowHeight = g.MeasureString("平均动脉压", Font).Height;
                    MedSymbol symbol = null;
                    float     symbolPosX = 0, symbolStringPosY = 0, symbolPosY;
                    float     offX          = 5;
                    float     rowSplitWidth = 10; //行项与项之间距
                    symbolPosX = rectF.X + offX;
                    //symbolPosY = rectF.Y + (rowHeight) / 2;
                    symbolPosY       = rectF.Y + this.Height / 2;
                    symbolStringPosY = rectF.Y + this.Height / 2 - rowHeight / 2;

                    foreach (string str in _symbolDict.Keys)
                    {
                        idx++;
                        if (string.IsNullOrEmpty(str) || aliass.Contains(str))
                        {
                            continue;
                        }

                        float rowWidth = g.MeasureString(str, Font).Width + 4f;

                        if ((idx - 1) >= _startLegendIndex)
                        {
                            symbol = _symbolDict[str].LegengSymbol;
                            if ((symbolPosX + symbol.Size + offX + g.MeasureString(str, Font).Width + rowSplitWidth + offX) > rectF.Right)
                            {
                                break;
                            }
                            symbolPosY = rectF.Y + (this.Height - symbol.Size) / 2;
                            aliass.Add(str);
                            symbol.Draw(g, symbolPosX, symbolPosY);
                            symbolPosX += symbol.Size + offX; //加上偏移
                            using (SolidBrush solidBrush3 = new SolidBrush(symbol.Pen.Color))
                            {
                                g.DrawString(_symbolDict[str].LegengName, Font, solidBrush3, symbolPosX, symbolStringPosY);
                            }
                            symbolPosX += g.MeasureString(_symbolDict[str].LegengName, Font).Width + rowSplitWidth + offX;
                            index++;
                        }
                    }
                }
                _endLegendIndex = idx == 0 ? 0 : (idx - 1);
            }
            PaintEventHandler eventHandle = Events[_customDraw] as PaintEventHandler;

            if (eventHandle != null)
            {
                eventHandle(this, new PaintEventArgs(g, ClientRectangle));
            }
        }