Exemplo n.º 1
0
        public CarWear(List <Part> carWear, int dNo)
        {
            InitializeComponent();
            newWear(carWear, dNo);


            Invalidate();
            WearPanel.Invalidate();
        }
Exemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Wear.Count > 0)
            {
                x = WearPanel.Width;
                y = WearPanel.Height;

                Graphics g = WearPanel.CreateGraphics();

                // draw the pattern
                try
                {
                    g.Clear(Color.White);

                    Decimal yMax = (Decimal)(y - pH * 2 - 90);

                    for (int i = 0; i < Wear.Count; i++)
                    {
                        Part p = Wear[i];


                        int     x1 = (i + 1) * x / (Wear.Count + 1) - pW;
                        Decimal y1 = yMax * p.Wear / 100;
                        Decimal y2 = yMax * p.Reliability / 100;
                        //Decimal y3 = yMax;

                        int yc = pH;

                        g.DrawRectangle(Pens.Black, x1, yc, pW * 2, (int)yMax);

                        if (y2 > 0)
                        {
                            if (y2 > yMax)
                            {
                                g.FillRectangle(Brushes.Green, x1, (int)(yc), pW * 2, (int)yMax);
                            }
                            else
                            {
                                g.FillRectangle(Brushes.Green, x1, (int)(yc + Math.Ceiling(yMax - y2)), pW * 2, (int)y2);
                            }
                        }

                        if (y1 > 0)
                        {
                            g.FillRectangle(Brushes.Red, x1 + (pW), (int)(yc + Math.Ceiling(yMax - y1)), (pW), (int)y1);
                        }


                        DrawText(g, p.Wear.ToString() + "%", (float)(x1 + pW * 2), (float)(yc + yMax - y1), true, Color.Red, 7f);
                        if (y2 > yMax)
                        {
                            DrawText(g, p.Reliability.ToString() + "%", (float)(x1), (float)(yc), false, Color.White, 7f);
                        }
                        else
                        {
                            DrawText(g, p.Reliability.ToString() + "%", (float)(x1), (float)(yc + yMax - y2), false, Color.White, 7f);
                        }

                        DrawText(g, p.Name, (float)(x1), (float)(yc + yMax), true, Color.Black, 10f);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
                finally
                {
                    g.Dispose();
                }
            }

            base.OnPaint(e);
        }