Example #1
0
 public SevenSegmentListItem(SevenSegmentDesigner owner)
     : base(owner.Component)
 {
     _SevenSegment = (HMISevenSegment2)owner.Component;
 }
        private void RefreshImage()
        {
            Graphics gr_dest = null;

            this.StaticImageRatio = (float)((double)Properties.Resources.RedZero.Height / ((double)(Properties.Resources.RedZero.Width * this.m_NumberOfDigits) * 1.1));
            //************************************************************
            //* Calculate the size ratio of the original t resized image
            //************************************************************
            float WidthRatio  = (float)((double)this.Width / ((double)(Properties.Resources.RedZero.Width * this.m_NumberOfDigits) * 1.1));
            float HeightRatio = (float)((double)this.Height / (double)Properties.Resources.RedZero.Height);

            //========================================================
            if (WidthRatio >= HeightRatio)
            {
                this.x          = (float)this.Width;
                this.y          = (float)((double)Properties.Resources.RedZero.Height / (double)(Properties.Resources.RedZero.Width * this.m_NumberOfDigits) * (double)this.Width);
                this.ImageRatio = HeightRatio;
            }
            else
            {
                this.y = (float)this.Height;
                if (!(this.Height > 0 && Properties.Resources.LED7Segment0Red.Height > 0))
                {
                    this.x = 1.0F;
                }
                else
                {
                    this.x = (float)((double)(Properties.Resources.RedZero.Width * this.m_NumberOfDigits) * 1.1 / (double)Properties.Resources.RedZero.Height * (double)this.Height);
                }
                this.ImageRatio = WidthRatio;
            }
            //==============================================================
            //************************************************
            //* Create a text rectangle and align to center
            //************************************************
            if (this.ImageRatio > 0.0F)
            {
                this.TextRectangle.X      = 0;
                this.TextRectangle.Y      = Convert.ToInt32(Math.Truncate(Math.Round((double)this.Height * 0.04)));
                this.TextRectangle.Width  = this.Width;
                this.TextRectangle.Height = Convert.ToInt32(Math.Truncate(Math.Round((double)this.Height * 0.18)));
                if (this.TextBrush == null)
                {
                    this.TextBrush = new SolidBrush(base.ForeColor);
                }
                //============================================================
                //* If number of digits is more than default image size (4), then draw left meter over right

                int LEDWidth  = Convert.ToInt32((float)Properties.Resources.RedEight.Width * this.ImageRatio);
                int LEDHeight = Convert.ToInt32((float)Properties.Resources.RedEight.Height * this.ImageRatio);

                //****************************************************************
                // Create Scaled LED images so it will draw faster in Paint event
                //****************************************************************
                int i = 0;
                //****************************************
                //* Draw each of the RED digits
                //****************************************
                for (i = 0; i <= 11; i++)
                {
                    if (this.RedLED[i] != null)
                    {
                        this.RedLED[i].Dispose();
                    }
                    this.RedLED[i] = new Bitmap(LEDWidth, LEDHeight);
                    gr_dest        = Graphics.FromImage(this.RedLED[i]);
                    gr_dest.ScaleTransform((float)(0.5 * ImageRatio), (float)(0.5 * ImageRatio));
                    HMISevenSegment2.SetNumber(gr_dest, i, Color.Red, true);
                }

                //****************************************
                //* Draw each of the Green  digits
                //****************************************
                int r = 0;
                for (r = 0; r <= 11; r++)
                {
                    if (this.GreenLED[r] != null)
                    {
                        this.GreenLED[r].Dispose();
                    }
                    this.GreenLED[r] = new Bitmap(LEDWidth, LEDHeight);
                    gr_dest          = Graphics.FromImage(this.GreenLED[r]);
                    gr_dest.ScaleTransform((float)(0.5 * ImageRatio), (float)(0.5 * ImageRatio));
                    HMISevenSegment2.SetNumber(gr_dest, r, Color.Green, true);
                }
                //* Draw the decimal point to the bitmap

                this.RedDecimalImage = new Bitmap(Convert.ToInt32((float)Properties.Resources.RedDecimal.Width * this.ImageRatio), Convert.ToInt32((float)Properties.Resources.RedDecimal.Height * this.ImageRatio));
                gr_dest = Graphics.FromImage(this.RedDecimalImage);
                gr_dest.DrawImage(Properties.Resources.RedDecimal, 0, 0, this.RedDecimalImage.Width, this.RedDecimalImage.Height);
                this.GreenDecimalImage = new Bitmap(Convert.ToInt32((float)Properties.Resources.GreenDecimal.Width * this.ImageRatio), Convert.ToInt32((float)Properties.Resources.GreenDecimal.Height * this.ImageRatio));
                gr_dest = Graphics.FromImage(this.GreenDecimalImage);
                gr_dest.DrawImage(Properties.Resources.GreenDecimal, 0, 0, this.GreenDecimalImage.Width, this.GreenDecimalImage.Height);


                //* Perform some cleanup
                gr_dest.Dispose();
                if (this._backBuffer != null)
                {
                    this._backBuffer.Dispose();
                }
                this._backBuffer = new Bitmap(this.Width, this.Height);

                this.Invalidate();
            }
        }