Beispiel #1
0
        private void DrawgaugeLinear(PaintEventArgs p)
        {
            m_TextOverlapPixels = (int)Math.Ceiling((double)m_MaxTickStackingDepth / 2.0);


            if (m_Orientation == Orientation.Vertical)
            {
                m_PixelsHigh = this.Size.Height - 1;
            }
            else
            {
                m_PixelsHigh = this.Size.Width - 1;
            }

            m_PixelsLow = 0;

            m_ClipLow  = m_PixelsLow;
            m_ClipHigh = m_PixelsHigh;
            //上下边界进行初始化确认
            if (this.m_PixelsLow < this.m_ClipLow + m_TextOverlapPixels)
            {
                this.m_PixelsLow = this.m_ClipLow + m_TextOverlapPixels;
            }
            if (this.m_PixelsHigh > this.m_ClipHigh - m_TextOverlapPixels)
            {
                this.m_PixelsHigh = this.m_ClipHigh - m_TextOverlapPixels;
            }

            if (m_Orientation == Orientation.Vertical)
            {
                if (m_Direction == SideDirection.LeftToRight)
                {
                    Pen TickPen = new Pen(m_TickColor, 1);

                    var r4 = new Rectangle(this.Width - m_Margin - 4 - (m_trackerSize.Width - 8), m_PixelsLow, m_trackerSize.Width - 8, m_PixelsHigh - m_PixelsLow);
                    p.Graphics.FillRectangle(new SolidBrush(m_trackLineColor), r4);
                    BorderSimple.Draw(p, r4, BorderStyleSimple.Sunken, Color.Gray);
                    //p.Graphics.DrawLine(TickPen, m_Margin + m_TickMajorLength+m_PointerSize, m_PixelsHigh, m_Margin + m_TickMajorLength+ m_PointerSize, m_PixelsLow);

                    //Draw Pointer
                    var r3     = new Rectangle(this.Width - m_Margin - m_trackerSize.Width, m_ClipHigh - ValueToPixels(m_Value) - m_trackerSize.Height / 2, m_trackerSize.Width, m_trackerSize.Height);
                    var points = GetPointerPoints(r3, Direction.Right);
                    p.Graphics.FillRectangle(new SolidBrush(m_trackerColor), r3);
                    BorderSimple.Draw(p, r3, BorderStyleSimple.Raised, m_trackerColor);



                    foreach (var item in m_ListTickMajor)
                    {
                        p.Graphics.DrawLine(TickPen, this.Width - m_Margin - m_TickMajorLength - m_trackerSize.Width, ValueToPixels(item.LocationValue), this.Width - m_Margin - m_trackerSize.Width, ValueToPixels(item.LocationValue));

                        //  var r = new Rectangle(this.Width - m_Margin -m_trackerSize.Width - m_TickMajorLength - m_LabelSpace - m_MaxTickTextWidth, m_ClipHigh - ValueToPixels(item.LocationValue) - m_MaxTickTextHeight / 2, m_MaxTickTextWidth, m_MaxTickTextHeight);
                        var r = new Rectangle(this.Width - m_Margin - m_trackerSize.Width - m_TickMajorLength - m_LabelSpace - m_MaxTickTextWidth, m_ClipHigh - ValueToPixels(item.LocationValue) - m_MaxTickTextHeight / 2, m_MaxTickTextWidth, m_MaxTickTextHeight);

                        p.Graphics.DrawString(Math.Round(item.LocationValue, m_decimals).ToString("F" + m_decimals.ToString()), this.Font, new SolidBrush(m_TextColor), r);
                        //  p.Graphics.DrawString("0.000", this.Font, new SolidBrush(m_TextColor), r);
                    }


                    foreach (var item in m_ListTickMinor)
                    {
                        p.Graphics.DrawLine(TickPen, this.Width - m_trackerSize.Width - m_Margin, ValueToPixels(item.LocationValue), this.Width - m_trackerSize.Width - m_Margin - m_TickMinorLength, ValueToPixels(item.LocationValue));
                    }
                }
                else
                {
                    ////画边框线
                    Pen TickPen = new Pen(m_TickColor, 1);
                    var r4      = new Rectangle(m_Margin + 4, m_PixelsLow, m_trackerSize.Width - 8, m_PixelsHigh - m_PixelsLow);
                    p.Graphics.FillRectangle(new SolidBrush(m_trackLineColor), r4);
                    BorderSimple.Draw(p, r4, BorderStyleSimple.Sunken, Color.Gray);
                    //p.Graphics.DrawLine(TickPen, m_Margin + m_TickMajorLength+m_PointerSize, m_PixelsHigh, m_Margin + m_TickMajorLength+ m_PointerSize, m_PixelsLow);


                    //Draw Pointer
                    var r3     = new Rectangle(m_Margin, m_ClipHigh - ValueToPixels(m_Value) - m_trackerSize.Height / 2, m_trackerSize.Width, m_trackerSize.Height);
                    var points = GetPointerPoints(r3, Direction.Right);
                    p.Graphics.FillRectangle(new SolidBrush(m_trackerColor), r3);
                    BorderSimple.Draw(p, r3, BorderStyleSimple.Raised, m_trackerColor);


                    foreach (var item in m_ListTickMajor)
                    {
                        p.Graphics.DrawLine(TickPen, m_Margin + m_trackerSize.Width, ValueToPixels(item.LocationValue), m_Margin + m_trackerSize.Width + item.Length, ValueToPixels(item.LocationValue));
                        //确认画Label数值的位置
                        var r = new Rectangle(m_Margin + m_TickMajorLength + m_trackerSize.Width + m_LabelSpace, m_ClipHigh - ValueToPixels(item.LocationValue) - m_MaxTickTextHeight / 2, m_MaxTickTextWidth, m_MaxTickTextHeight);
                        p.Graphics.DrawString(Math.Round(item.LocationValue, m_decimals).ToString("F" + m_decimals.ToString()), this.Font, new SolidBrush(m_TextColor), r);
                    }
                    foreach (var item in m_ListTickMinor)
                    {
                        p.Graphics.DrawLine(TickPen, m_Margin + m_trackerSize.Width, ValueToPixels(item.LocationValue), 2 + m_TickMinorLength + m_trackerSize.Width, ValueToPixels(item.LocationValue));
                    }
                }
            }
            //水平状态下的内容
            else
            {
                if (m_Direction == SideDirection.LeftToRight)
                {
                    var r4 = new Rectangle(m_PixelsLow, m_Margin + 4, m_PixelsHigh - m_PixelsLow, m_trackerSize.Height - 8);
                    p.Graphics.FillRectangle(new SolidBrush(m_trackLineColor), r4);
                    BorderSimple.Draw(p, r4, BorderStyleSimple.Sunken, Color.Gray);

                    //Draw Pointer
                    var r3     = new Rectangle(ValueToPixels(m_Value) - m_trackerSize.Width / 2, m_Margin, m_trackerSize.Width, m_trackerSize.Height);
                    var points = GetPointerPoints(r3, Direction.Right);
                    p.Graphics.FillRectangle(new SolidBrush(m_trackerColor), r3);
                    BorderSimple.Draw(p, r3, BorderStyleSimple.Raised, m_trackerColor);



                    Pen TickPen = new Pen(m_TickColor, 1);

                    //p.Graphics.DrawLine(TickPen, m_PixelsHigh, m_Margin + m_TickMajorLength + m_trackerSize.Height, m_PixelsLow, m_Margin + m_TickMajorLength + m_trackerSize.Height);


                    foreach (var item in m_ListTickMajor)
                    {
                        p.Graphics.DrawLine(TickPen, ValueToPixels(item.LocationValue), m_Margin + m_trackerSize.Height, ValueToPixels(item.LocationValue), m_Margin + m_trackerSize.Height + m_TickMajorLength);

                        var r = new Rectangle(ValueToPixels(item.LocationValue) - item.TextSize.Width / 4, m_Margin + m_trackerSize.Height + m_TickMajorLength + m_LabelSpace, item.TextSize.Width, item.TextSize.Height);

                        p.Graphics.DrawString(Math.Round(item.LocationValue, m_decimals).ToString("F" + m_decimals.ToString()), this.Font, new SolidBrush(m_TextColor), r);
                    }


                    foreach (var item in m_ListTickMinor)
                    {
                        p.Graphics.DrawLine(TickPen, ValueToPixels(item.LocationValue), m_trackerSize.Height + m_TickMajorLength + m_Margin, ValueToPixels(item.LocationValue), m_trackerSize.Height + m_TickMajorLength + m_Margin - m_TickMinorLength);
                    }
                }
                else
                {
                    var r4 = new Rectangle(m_PixelsLow, this.Height - (m_Margin + m_trackerSize.Height - 4), m_PixelsHigh - m_PixelsLow, m_trackerSize.Height - 8);
                    p.Graphics.FillRectangle(new SolidBrush(m_trackLineColor), r4);
                    BorderSimple.Draw(p, r4, BorderStyleSimple.Sunken, Color.Gray);

                    //Draw Pointer
                    var r3 = new Rectangle(ValueToPixels(m_Value) - m_trackerSize.Width / 2, this.Height - m_Margin - m_trackerSize.Height, m_trackerSize.Width, m_trackerSize.Height);
                    p.Graphics.FillRectangle(new SolidBrush(m_trackerColor), r3);
                    BorderSimple.Draw(p, r3, BorderStyleSimple.Raised, m_trackerColor);



                    Pen TickPen = new Pen(m_TickColor, 1);

                    //   p.Graphics.DrawLine(TickPen, m_PixelsHigh,this.Height- m_Margin - m_TickMajorLength - m_trackerSize.Width, m_PixelsLow, this.Height - m_Margin - m_TickMajorLength - m_trackerSize.Width);


                    foreach (var item in m_ListTickMajor)
                    {
                        p.Graphics.DrawLine(TickPen, ValueToPixels(item.LocationValue), this.Height - m_Margin - m_trackerSize.Height, ValueToPixels(item.LocationValue), this.Height - m_Margin - m_trackerSize.Height - m_TickMajorLength);

                        var r = new Rectangle(ValueToPixels(item.LocationValue) - item.TextSize.Width / 4, this.Height - m_Margin * 2 - m_TickMajorLength - m_trackerSize.Height - m_LabelSpace - m_MaxTickTextHeight / 2, item.TextSize.Width, item.TextSize.Height);

                        p.Graphics.DrawString(Math.Round(item.LocationValue, m_decimals).ToString("F" + m_decimals.ToString()), this.Font, new SolidBrush(m_TextColor), r);
                    }


                    foreach (var item in m_ListTickMinor)
                    {
                        p.Graphics.DrawLine(TickPen, ValueToPixels(item.LocationValue), this.Height - m_TickMajorLength - m_trackerSize.Height - m_Margin, ValueToPixels(item.LocationValue), this.Height - m_TickMajorLength - m_trackerSize.Height - m_Margin + m_TickMinorLength);
                    }
                }
            }
        }
Beispiel #2
0
        public static void Draw(PaintEventArgs p, Rectangle r, BorderStyleSimple style, Color color)
        {
            Color color2;
            Color color3;
            Color color4;
            Color color5;

            if (color != SystemColors.Control)
            {
                color2 = iColors.Lighten2(color);
                color3 = iColors.Darken4(color);
                color4 = iColors.Lighten4(color);
                color5 = iColors.Darken2(color);
            }
            else
            {
                color2 = SystemColors.ControlLight;
                color3 = SystemColors.ControlDarkDark;
                color4 = SystemColors.ControlLightLight;
                color5 = SystemColors.ControlDark;
            }
            Color[] array = new Color[4];
            if (style == BorderStyleSimple.Raised)
            {
                array[0] = color2;
                array[1] = color3;
                array[2] = color4;
                array[3] = color5;
            }
            else if (style == BorderStyleSimple.Sunken)
            {
                array[0] = color5;
                array[1] = color4;
                array[2] = color3;
                array[3] = color2;
            }
            else if (style == BorderStyleSimple.Bump)
            {
                array[0] = color2;
                array[1] = color3;
                array[2] = color3;
                array[3] = color2;
            }
            else if (style == BorderStyleSimple.Etched)
            {
                array[0] = color5;
                array[1] = color4;
                array[2] = color4;
                array[3] = color5;
            }
            else if (style == BorderStyleSimple.RaisedInner)
            {
                array[0] = color4;
                array[1] = color5;
            }
            else if (style == BorderStyleSimple.RaisedOuter)
            {
                array[0] = color2;
                array[1] = color3;
            }
            else if (style == BorderStyleSimple.SunkenInner)
            {
                array[0] = color3;
                array[1] = color2;
            }
            else if (style == BorderStyleSimple.SunkenOuter)
            {
                array[0] = color5;
                array[1] = color4;
            }
            else if (style == BorderStyleSimple.Flat)
            {
                array[0] = Color.Black;
                array[1] = Color.Black;
            }
            Point[] points = BorderSimple.GetBorderUpperLeftPoints(p, r);
            p.Graphics.DrawLines(new Pen(array[0]), points);
            points = BorderSimple.GetBorderLowerRightPoints(p, r);
            p.Graphics.DrawLines(new Pen(array[1]), points);
            if (style == BorderStyleSimple.Raised || style == BorderStyleSimple.Sunken || style == BorderStyleSimple.Bump || style == BorderStyleSimple.Etched)
            {
                r.Inflate(-1, -1);
                points = BorderSimple.GetBorderUpperLeftPoints(p, r);
                p.Graphics.DrawLines(new Pen(array[2]), points);

                points = BorderSimple.GetBorderLowerRightPoints(p, r);
                p.Graphics.DrawLines(new Pen(array[3]), points);
            }
        }