Example #1
0
        private void DrawMultiLegend(ref Graphics g, Legends _Legends, int LegendWidth, int LegendHeight, bool ShowPointLegend, bool showMissingDataInLegend, int MultiLegendIndex, LegendsSequenceOrder legendSequenceOrder)
        {
            int i;
            SolidBrush BrTitle = new SolidBrush(m_LegendBodyColor);
            Legend _Legend;
            string LegendCaption = string.Empty;
            SizeF LegendTitleSize = g.MeasureString(m_LegendTitle, m_LegendFont);
            int LegendLeftPos = 0;

            float ImageRowHeight = LegendTitleSize.Height;  // image height set in single row when width exceeds then wrap in next row

            //change Increment
            int SetOnce = 0;
            //endchange
            switch (m_ThemeType)
            {
                case ThemeType.Symbol:
                    object BrLegend;
                    StringFormat _StringFormat = new StringFormat();
                    _StringFormat.Alignment = StringAlignment.Center;
                    _StringFormat.LineAlignment = StringAlignment.Center;
                    _StringFormat.FormatFlags = StringFormatFlags.NoClip;
                    for (i = 0; i <= _Legends.Count - 1; i++)
                    {
                        bool DrawLegendRequired = true;

                        //- Skip MissingData Legend if not required
                        if (i == m_Legends.Count - 1 && showMissingDataInLegend == false)
                        {
                            DrawLegendRequired = false;
                        }

                        if (DrawLegendRequired)
                        {
                            _Legend = _Legends[i];

                            LegendCaption = string.Empty;

                            //*** Pick Legend Title from Source Legend - [Caption] Doublespace [Title]
                            if (this.ShowLegendCaption)
                            {
                                LegendCaption = _Legend.Caption + " ";
                            }
                            else if (showMissingDataInLegend && i == m_Legends.Count - 1)
                            {
                                //- Show MissingData for Last Legend if Caption is blank
                                LegendCaption = _Legend.Caption + " ";
                            }

                            if (this.ShowLegendRange && (!(string.IsNullOrEmpty(_Legend.Title))))
                            {
                                LegendCaption += _Legend.Title;
                            }
                            if (this.ShowAreaCount)
                            {
                                LegendCaption += " (" + Convert.ToString(_Legend.ShapeCount) + ")";
                            }

                            //-Draw Symbol marchar
                            if (legendSequenceOrder == LegendsSequenceOrder.SingleRow)
                            {
                                _StringFormat.Alignment = StringAlignment.Near;

                                //- Show all symbols in single row (Horizontally)
                                //- Starting left position of Legend's Color box
                                LegendLeftPos += 10;

                                //-show Symbol box adjacent (right) to previous Legend
                                if (_Legend.SymbolImage == "" || File.Exists(_Legend.SymbolImage) == false)
                                {
                                    BrLegend = new SolidBrush(_Legend.Color);
                                    g.DrawString(_Legend.MarkerChar.ToString(), _Legend.MarkerFont, (SolidBrush)BrLegend, LegendLeftPos, LegendTitleSize.Height + 5 + (_Legend.MarkerFont.Size / 3), _StringFormat);
                                    //_StringFormat

                                    LegendLeftPos += (int)(g.MeasureString(_Legend.MarkerChar.ToString(), _Legend.MarkerFont).Width);
                                }
                                else
                                {
                                    BrLegend = Image.FromFile(_Legend.SymbolImage);
                                    g.DrawImage((Image)BrLegend, LegendLeftPos, LegendTitleSize.Height + 5 + 6, Math.Min(16, ((Image)BrLegend).Width), Math.Min(13, ((Image)BrLegend).Height));

                                    LegendLeftPos += LegendWidth;
                                }
                            }
                            else
                            {
                                //-Show all Symbols in single column
                                if (_Legend.SymbolImage == "" || File.Exists(_Legend.SymbolImage) == false)
                                {
                                    BrLegend = new SolidBrush(_Legend.Color);
                                    g.DrawString(_Legend.MarkerChar.ToString(), _Legend.MarkerFont, (SolidBrush)BrLegend, 30, LegendTitleSize.Height + 5 + (_Legend.MarkerFont.Size / 2) + (i * LegendHeight), _StringFormat);
                                    //_StringFormat
                                }
                                else
                                {
                                    BrLegend = Image.FromFile(_Legend.SymbolImage);
                                    g.DrawImage((Image)BrLegend, 10, LegendTitleSize.Height + 5 + (i * LegendHeight) + 6, Math.Min(16, ((Image)BrLegend).Width), Math.Min(13, ((Image)BrLegend).Height));
                                }
                            }

                            if (legendSequenceOrder == LegendsSequenceOrder.SingleColumn)
                            {
                                //-Show Legend Caption or Range
                                g.DrawString(LegendCaption, m_LegendBodyFont, BrTitle, LegendWidth + 20, LegendTitleSize.Height + 5 + (i * LegendHeight));
                            }
                            else
                            {
                                //- if in single row, then draw caption next to Symbol Box
                                LegendLeftPos += 10;
                                g.DrawString(LegendCaption.Trim(), m_LegendBodyFont, BrTitle, LegendLeftPos, LegendTitleSize.Height + 5);

                                //- For next Legend, increment left position by caption width.
                                LegendLeftPos += (int)(g.MeasureString(LegendCaption.Trim(), m_LegendBodyFont).Width);
                            }

                            //Range Title
                        }
                    }

                    BrLegend = new SolidBrush(Color.Black);      // BrLegend object is equalled to SolidBrush so that .Dispose() can be used. SolidBrush has no significance here.
                    if ((BrLegend != null))
                    {
                        ((SolidBrush)BrLegend).Dispose();
                    }

                    _StringFormat.Dispose();
                    break;
                //TODO Handle MultiColorTheme case
                case ThemeType.Label:
                    int PreviousLegendHeight = 0;
                    SizeF LegendSize;

                    BrLegend = new SolidBrush(Color.Black);
                    for (i = 0; i <= _Legends.Count - 1; i++)
                    {
                        _Legend = _Legends[i];

                        LegendCaption = string.Empty;

                        //*** Pick Legend Title from Source Legend - [Caption] Doublespace [Title]
                        if (this.ShowLegendCaption)
                        {
                            LegendCaption = _Legend.Caption + " ";
                        }
                        else if (showMissingDataInLegend && i == m_Legends.Count - 1)
                        {
                            //- Show MissingData for Last Legend if Caption is blank
                            LegendCaption = _Legend.Caption + " ";
                        }

                        if (this.ShowLegendRange && (!(string.IsNullOrEmpty(_Legend.Title))))
                        {
                            LegendCaption += _Legend.Title;
                        }
                        if (this.ShowAreaCount)
                        {
                            LegendCaption += " (" + Convert.ToString(_Legend.ShapeCount) + ")";
                        }

                        LegendSize = g.MeasureString(LegendCaption, _Legend.MarkerFont);
                        LegendHeight = (int)(LegendSize.Height);
                        LegendWidth = (int)(LegendSize.Width);

                        BrLegend = new SolidBrush(_Legend.Color);

                        //accomodate legend size to display large text
                        g.SetClip(new Rectangle(0, (int)LegendTitleSize.Height + PreviousLegendHeight + 5, (int)(15 + LegendWidth), LegendHeight));
                        g.DrawString(LegendCaption, _Legend.MarkerFont, (SolidBrush)BrLegend, 10, LegendTitleSize.Height + PreviousLegendHeight + 5);

                        g.ResetClip();

                        PreviousLegendHeight += LegendHeight;
                    }

                    ((SolidBrush)BrLegend).Dispose();
                    break;
                //TODO Handle MultiColorTheme case
                case ThemeType.Color:
                case ThemeType.Hatch:

                    LegendLeftPos = 0;

                    for (i = 0; i <= _Legends.Count - 1; i++)
                    {
                        bool DrawLegendRequired = true;

                        //- Skip MissingData Legend if not required
                        if (i == m_Legends.Count - 1 && showMissingDataInLegend == false)
                        {
                            DrawLegendRequired = false;
                        }

                        if (DrawLegendRequired)
                        {

                            _Legend = _Legends[i];

                            LegendCaption = string.Empty;

                            //*** Pick Title from Source Legend
                            //--Start Change C1  - display - <Caption>Doublespace<Title>
                            if (this.ShowLegendCaption)
                            {
                                LegendCaption = _Legend.Caption + " ";
                            }
                            else if (showMissingDataInLegend && i == m_Legends.Count - 1)
                            {
                                //- Show MissingData for Last Legend if Caption is blank
                                LegendCaption = _Legend.Caption + " ";
                            }

                            if (this.ShowLegendRange && (!(string.IsNullOrEmpty(_Legend.Title))))
                            {
                                LegendCaption += _Legend.Title;
                            }
                            if (this.ShowAreaCount)
                            {
                                LegendCaption += " (" + Convert.ToString(_Legend.ShapeCount) + ")";
                            }

                            if (_Legend.FillStyle == FillStyle.Solid)
                            {
                                BrLegend = new SolidBrush(_Legend.Color);
                            }
                            else if (_Legend.FillStyle == FillStyle.Transparent)
                            {
                                BrLegend = new SolidBrush(Color.Transparent);
                            }
                            else
                            {
                                BrLegend = new HatchBrush((HatchStyle)_Legend.FillStyle, _Legend.Color, Color.Transparent);
                            }

                            if (m_ThemeType == ThemeType.Color & ShowPointLegend == true)
                            {
                                g.FillRectangle((Brush)BrLegend, 10, LegendTitleSize.Height + (i * LegendHeight), (int)LegendWidth / 2, LegendHeight - 2);
                                //Half Color Box
                                switch (_Legend.MarkerType)
                                {
                                    case MarkerStyle.Circle:
                                        g.FillEllipse((Brush)BrLegend, 35, LegendTitleSize.Height + (i * LegendHeight) + 5, 10, 10);
                                        //Circle
                                        break;
                                    case MarkerStyle.Square:
                                        g.FillRectangle((Brush)BrLegend, 35, LegendTitleSize.Height + (i * LegendHeight) + 5, 10, 10);
                                        //Square
                                        break;
                                    case MarkerStyle.Triangle:
                                        PointF[] Vertex = new PointF[3];
                                        //Triangle
                                        Vertex[0] = new PointF(40, LegendTitleSize.Height + (i * LegendHeight) + 5);
                                        Vertex[1] = new PointF(35, LegendTitleSize.Height + (i * LegendHeight) + 15);
                                        Vertex[2] = new PointF(45, LegendTitleSize.Height + (i * LegendHeight) + 15);
                                        g.FillPolygon((Brush)BrLegend, Vertex);
                                        break;
                                    case MarkerStyle.Cross:
                                        Pen Pn = new Pen(_Legend.Color);
                                        //Cross
                                        g.DrawLine(Pn, 35, LegendTitleSize.Height + (i * LegendHeight) + 10, 45, LegendTitleSize.Height + (i * LegendHeight) + 10);
                                        g.DrawLine(Pn, 40, LegendTitleSize.Height + (i * LegendHeight) + 5, 40, LegendTitleSize.Height + (i * LegendHeight) + 15);
                                        Pn.Dispose();
                                        break;
                                }
                            }
                            else
                            {
                                if (m_MultiLegend == true)
                                {
                                    g.FillRectangle((Brush)BrLegend, 10 + (LegendWidth * MultiLegendIndex) + MultiLegendIndex, LegendTitleSize.Height + (i * LegendHeight) + 5, LegendWidth, LegendHeight - 2);
                                    //Color Box
                                }
                                else
                                {
                                    //If legend postion exceeds max Legend width then reset the left position and height to wrap text
                                    if (legendSequenceOrder == LegendsSequenceOrder.SingleRow && (m_LegendMaxWidth) <= ((g.MeasureString(LegendCaption.Trim(), m_LegendBodyFont).Width) + LegendLeftPos + LegendWidth))
                                    {
                                        LegendLeftPos = 0;
                                        LegendTitleSize.Height = LegendTitleSize.Height + ImageRowHeight;
                                    }

                                    //Color Box
                                    if (legendSequenceOrder == LegendsSequenceOrder.SingleRow)
                                    {
                                        //- Starting left position of Legend's Color box
                                        LegendLeftPos += 1; //10  di Profiles

                                        //-show color box adjacent (right) to previous Legend
                                        g.FillRectangle((Brush)BrLegend, LegendLeftPos, LegendTitleSize.Height + 5, LegendWidth, LegendHeight - 2);

                                        LegendLeftPos += LegendWidth;
                                    }
                                    else
                                    {
                                        //-show color box below previous Legend
                                        g.FillRectangle((Brush)BrLegend, 10, LegendTitleSize.Height + (i * LegendHeight) + 5, LegendWidth, LegendHeight - 2);
                                    }

                                }

                            }
                            if (m_MultiLegend == true)
                            {
                                if (MultiLegendIndex == m_MultiLegendCol.Count - 1)
                                {
                                    //Range Title
                                    g.DrawString(LegendCaption.Trim(), m_LegendBodyFont, BrTitle, (LegendWidth * m_MultiLegendCol.Count) + 20, LegendTitleSize.Height + 5 + (i * LegendHeight));
                                }
                            }
                            else
                            {
                                //Draw Range Title string
                                if (legendSequenceOrder == LegendsSequenceOrder.SingleColumn)
                                {
                                    g.DrawString(LegendCaption.Trim(), m_LegendBodyFont, BrTitle, LegendWidth + 20, LegendTitleSize.Height + 5 + (i * LegendHeight));
                                }
                                else
                                {
                                    //- if in single row, then draw caption next to Color Box
                                    LegendLeftPos += 1; //10  di Profiles
                                    g.DrawString(LegendCaption.Trim(), m_LegendBodyFont, BrTitle, LegendLeftPos, LegendTitleSize.Height + 5 );

                                    //- For next Legend, increment left position by caption width.
                                    LegendLeftPos += (int)(g.MeasureString(LegendCaption.Trim(), m_LegendBodyFont).Width);

                                }
                            }

                        }
                    }

                    //if ((BrLegend != null))
                    //    BrLegend = null;

                    break;
            }
            BrTitle.Dispose();
        }
Example #2
0
 private void DrawMultiLegend(ref Graphics g, Legends _Legends, int LegendWidth, int LegendHeight)
 {
     bool ShowPointLegend = false;
     int MultiLegendIndex = -1;
     DrawMultiLegend(ref g, _Legends, LegendWidth, LegendHeight, ShowPointLegend, true, MultiLegendIndex, LegendsSequenceOrder.SingleColumn);
 }
Example #3
0
 private void DrawMultiLegend(ref Graphics g, Legends _Legends, int LegendWidth, int LegendHeight, bool ShowPointLegend, bool showMissingDataInLegend)
 {
     int MultiLegendIndex = -1;
     DrawMultiLegend(ref g, _Legends, LegendWidth, LegendHeight, ShowPointLegend, showMissingDataInLegend, MultiLegendIndex, LegendsSequenceOrder.SingleColumn);
 }
Example #4
0
        private void BuildRangeColor(Color p_StartColor, Color p_EndColor, Legends _Legends)
        {
            int iBreaks = m_BreakCount;
            int A1;
            int A2;

            int R1;
            int R2;

            int G1;
            int G2;

            int B1;
            int B2;

            int TA1;
            int TR1;
            int TG1;
            int TB1;

            float AInterval;
            float RInterval;
            float GInterval;
            float BInterval;
            int iCtr;

            if ((_Legends == null))
            {
                iBreaks = m_BreakCount;
            }
            else
            {
                iBreaks = _Legends.Count - 1;
            }

            A1 = p_StartColor.A;
            R1 = p_StartColor.R;
            G1 = p_StartColor.G;
            B1 = p_StartColor.B;

            A2 = p_EndColor.A;
            R2 = p_EndColor.R;
            G2 = p_EndColor.G;
            B2 = p_EndColor.B;

            //-- get the difference between the R, G, B and divide it by number of breaks to get the interval

            AInterval = Convert.ToSingle(Math.Abs((A1 - A2) / (iBreaks - 1)));
            RInterval = Convert.ToSingle(Math.Abs((R1 - R2) / (iBreaks - 1)));
            GInterval = Convert.ToSingle(Math.Abs((G1 - G2) / (iBreaks - 1)));
            BInterval = Convert.ToSingle(Math.Abs((B1 - B2) / (iBreaks - 1)));

            for (iCtr = 1; iCtr <= iBreaks; iCtr++)
            {
                if (iCtr == 1)
                {
                   //-- first color
                      TA1 = p_StartColor.A;
                   TR1 = p_StartColor.R;
                    TG1 = p_StartColor.G;
                    TB1 = p_StartColor.B;
                }
                else if (iCtr == iBreaks)
                {
                    //-- last color
                    TA1 = p_EndColor.A;
                    TR1 = p_EndColor.R;
                    TG1 = p_EndColor.G;
                    TB1 = p_EndColor.B;
                }
                else
                {

                    if (A1 > A2)
                    {
                        TA1 = Convert.ToInt16(A1 - (AInterval * (iCtr - 1)));
                    }
                    else
                    {
                        TA1 = Convert.ToInt16(A1 + (AInterval * (iCtr - 1)));
                    }

                    if (R1 > R2)
                    {
                        TR1 = Convert.ToInt16(R1 - (RInterval * (iCtr - 1)));
                    }
                    else
                    {
                        TR1 = Convert.ToInt16(R1 + (RInterval * (iCtr - 1)));
                    }
                    if (G1 > G2)
                    {
                        TG1 = Convert.ToInt16(G1 - (GInterval * (iCtr - 1)));
                    }
                    else
                    {
                        TG1 = Convert.ToInt16(G1 + (GInterval * (iCtr - 1)));
                    }

                    if (B1 > B2)
                    {
                        TB1 = Convert.ToInt16(B1 - (BInterval * (iCtr - 1)));
                    }
                    else
                    {
                        TB1 = Convert.ToInt16(B1 + (BInterval * (iCtr - 1)));
                    }

                }

                if ((_Legends == null))
                {
                    m_Legends[iCtr - 1].Color = Color.FromArgb(Math.Abs(TA1),Math.Abs(TR1), Math.Abs(TG1), Math.Abs(TB1));
                }
                else
                {
                    _Legends[iCtr - 1].Color = Color.FromArgb(Math.Abs(TA1), Math.Abs(TR1), Math.Abs(TG1), Math.Abs(TB1));
                }

            }
        }