示例#1
0
 // Insert a bar item at a specified index
 protected void InsertItem(int nIndex, HBarData item)
 {
     arrItem.Insert(nIndex, item);
     if (dMaximumValue < item.Value)
     {
         dMaximumValue = item.Value;
     }
 }
示例#2
0
        // Get a bar item
        public bool GetAt(int nIndex, out HBarData bar)
        {
            bar = null;
            if (nIndex < 0 || arrItem.Count <= nIndex)
            {
                return(false);
            }

            bar = ((HBarData)arrItem[nIndex]);
            return(true);
        }
示例#3
0
        // Add a new bar item
        protected void AddItem(HBarData item)
        {
            arrItem.Add(item);

            // Set first value as the maximum. If control modified to support negeative numbers
            // This will help to calculate true maximum, the reason is that the default is 0
            // which is always bigger than negative values, thus it's always bigger than all
            // values, while maximum value of array is something else(it's also negative) not 0
            if (arrItem.Count == 1)
            {
                dMaximumValue = item.Value;
            }
            else if (dMaximumValue < item.Value)
            {
                dMaximumValue = item.Value;
            }
        }
示例#4
0
        // Insert a bar at a specified index
        protected void InsertItem(int nIndex, double dValue, string strLabel, Color colorBar)
        {
            HBarData item = new HBarData(dValue, strLabel, colorBar);

            InsertItem(nIndex, item);
        }
示例#5
0
        // Add a new bar
        protected void AddItem(double dValue, string strLabel, Color colorBar)
        {
            HBarData item = new HBarData(dValue, strLabel, colorBar);

            AddItem(item);
        }
示例#6
0
        // Draw a bar with label & valu using specified index bouned to the
        // specified rectangle of the selected bitmap of specified graphics object
        private void DrawBar(Graphics gr, RectangleF rectBar, HBarData bar)
        {
            // Some calculations
            if (rectBar.Height <= 0)
            {
                rectBar.Height = 1;
            }
            int nAlphaStart = (int)(185 + 5 * rectBar.Width / 24),
                nAlphaEnd   = (int)(10 + 4 * rectBar.Width / 24);

            if (nAlphaStart > 255)
            {
                nAlphaStart = 255;
            }
            else if (nAlphaStart < 0)
            {
                nAlphaStart = 0;
            }

            if (nAlphaEnd > 255)
            {
                nAlphaEnd = 255;
            }
            else if (nAlphaEnd < 0)
            {
                nAlphaEnd = 0;
            }


            Color ColorBacklight    = bar.Color;
            Color ColorBacklightEnd = Color.FromArgb(50, 0, 0, 0);
            Color ColorGlowStart    = Color.FromArgb(nAlphaEnd, 255, 255, 255);
            Color ColorGlowEnd      = Color.FromArgb(nAlphaStart, 255, 255, 255);
            Color ColorFillBK       = GetDarkerColor(bar.Color, 85);
            Color ColorBorder       = GetDarkerColor(bar.Color, 100);

            // Draw a single bar.
            #region BarItself
            RectangleF   er      = new RectangleF(rectBar.Left, rectBar.Top - rectBar.Height / 2, rectBar.Width * 2, rectBar.Height * 2);
            GraphicsPath rctPath = new GraphicsPath();
            rctPath.AddEllipse(er);

            PathGradientBrush pgr = new PathGradientBrush(rctPath);
            pgr.CenterPoint    = new PointF(rectBar.Right, rectBar.Top + rectBar.Height / 2);
            pgr.CenterColor    = ColorBacklight;
            pgr.SurroundColors = new Color[] { ColorBacklightEnd };

            RectangleF          rectGlow = new RectangleF(rectBar.Left, rectBar.Top, rectBar.Width / 2, rectBar.Height);
            LinearGradientBrush brGlow   = new LinearGradientBrush(
                new PointF(rectGlow.Right + 1, rectGlow.Top), new PointF(rectGlow.Left - 1, rectGlow.Top),
                ColorGlowStart, ColorGlowEnd);

            gr.FillRectangle(new SolidBrush(ColorFillBK), rectBar);
            //gr.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 0, 0)), rectBar);
            gr.FillRectangle(pgr, rectBar);
            gr.FillRectangle(brGlow, rectGlow);
            gr.DrawRectangle(new Pen(ColorBorder, 1), rectBar.Left, rectBar.Top, rectBar.Width, rectBar.Height);
            #endregion

            // Draw label
            if (Label.Visible)
            {
                float nLabelHeight = Label.Font.GetHeight(gr);
                gr.DrawString(
                    bar.Label,
                    Label.Font,
                    new SolidBrush(Label.Color),
                    new RectangleF(
                        rectBar.X,
                        rectBar.Bottom + nBarsGap,
                        rectBar.Width,
                        nLabelHeight));
            }

            // Draw value or %
            if (Values.Visible)
            {
                string strValue = string.Empty;
                if (Values.Mode == CValueProperty.ValueMode.Digit)
                {
                    strValue = bar.Value.ToString("F1");
                }
                else if (Values.Mode == CValueProperty.ValueMode.Percent)
                {
                    double dTotal = bars.TotalValue;
                    if (dTotal > 0)
                    {
                        strValue =
                            ((double)(bar.Value / dTotal)).ToString("P1",
                                                                    System.Globalization.CultureInfo.CurrentCulture);
                    }
                }

                float fValueHeight = Values.Font.GetHeight(gr);
                gr.DrawString(
                    strValue,
                    Values.Font,
                    new SolidBrush(Values.Color),
                    new RectangleF(
                        rectBar.X,
                        rectBar.Top - fValueHeight - 1,
                        rectBar.Width + 2 * nBarsGap,
                        fValueHeight));
            }
        }
示例#7
0
        private void CreateLabelFont(Graphics gr, SizeF sizeBar)
        {
            float fFontSize = 100 + (sizeBar.Width / 24);

            if (fFontSize <= 0)
            {
                fFontSize = 1;
            }


            // Set font style
            string    strFontName;
            FontStyle fntStyle;

            if (Label.Font == null)
            {
                strFontName = "Tahoma";
                fntStyle    = FontStyle.Regular;
            }
            else
            {
                strFontName = Label.Font.Name;
                fntStyle    = Label.Font.Style;
            }

            Label.Font = new Font(strFontName, fFontSize, fntStyle);

            // Get lengthiest label
            HBarData bar     = null;
            SizeF    sizeMax = new SizeF(0, 0);
            SizeF    sizeText;

            for (int i = 0; i < bars.Count; i++)
            {
                if (bars.GetAt(i, out bar))
                {
                    sizeText = gr.MeasureString(bar.Label, Label.Font);
                    if (sizeText.Width > sizeMax.Width)
                    {
                        sizeMax = sizeText;
                    }
                }
            }

            sizeText = sizeMax;

            // Fit text in client area if needed
            if (sizeText.Width > sizeBar.Width)
            {
                float fWidthRatio = sizeBar.Width / sizeText.Width;
                fFontSize = (Label.Font.Size * fWidthRatio);

                // Recreate font if needed
                if (fFontSize > 0)
                {
                    Label.Font.Dispose();
                    Label.Font = null;
                    Label.Font = new Font(strFontName, fFontSize, fntStyle);
                }
            }
        }
示例#8
0
        private void CreateValueFont(Graphics gr, SizeF sizeBar)
        {
            // Set font style
            string    strFontName;
            FontStyle fntStyle;
            float     fFontSize = 100 + (sizeBar.Width / 24);

            if (fFontSize <= 0)
            {
                fFontSize = 1;
            }

            if (Values.Font == null)
            {
                strFontName = "Tahoma";
                fntStyle    = FontStyle.Regular;
            }
            else
            {
                strFontName = Values.Font.Name;
                fntStyle    = Values.Font.Style;
            }

            Values.Font = new Font(strFontName, fFontSize, fntStyle);

            // Get lengthiest label
            HBarData bar             = null;
            string   strValue        = string.Empty;
            string   strLargestValue = string.Empty;
            double   dTotal          = bars.TotalValue;

            for (int i = 0; i < bars.Count; i++)
            {
                if (bars.GetAt(i, out bar))
                {
                    if (Values.Mode == CValueProperty.ValueMode.Digit)
                    {
                        strValue = String.Format("{0:F1}", bar.Value);
                    }
                    else if (Values.Mode == CValueProperty.ValueMode.Percent)
                    {
                        if (dTotal > 0)
                        {
                            strValue = ((double)(bar.Value / dTotal)).ToString("P1", System.Globalization.CultureInfo.CurrentCulture);
                        }
                    }

                    if (strValue.Length > strLargestValue.Length)
                    {
                        strLargestValue = strValue;
                    }
                }
            }

            SizeF sizeText = gr.MeasureString(strValue, Values.Font);

            // Fit text in client area if needed
            if (sizeText.Width > sizeBar.Width)
            {
                float fWidthRatio = sizeBar.Width / sizeText.Width;
                fFontSize = (Values.Font.Size * fWidthRatio);

                // Recreate font if needed
                if (fFontSize > 0)
                {
                    Values.Font.Dispose();
                    Values.Font = null;
                    Values.Font = new Font(strFontName, fFontSize, fntStyle);
                }
            }
        }
示例#9
0
 public bool GetAt(int nIndex, out HBarData bar)
 {
     return(bars.GetAt(nIndex, out bar));
 }