예제 #1
0
        private void PdcPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;
            Size     stringSize;

            using (var arial24bold = new Font("Arial", 24, FontStyle.Bold))
            {
                stringSize = Size.Ceiling(g.MeasureString("Simulador de Colméia",
                                                          arial24bold));
                g.FillEllipse(Brushes.Gray, new Rectangle(e.MarginBounds.X + 2,
                                                          e.MarginBounds.Y + 2, stringSize.Width + 30, stringSize.Height + 30));
                g.FillEllipse(Brushes.Black, new Rectangle(e.MarginBounds.X,
                                                           e.MarginBounds.Y, stringSize.Width + 30, stringSize.Height + 30));
                g.DrawString("Simulador de Colméia", arial24bold, Brushes.Gray,
                             e.MarginBounds.X + 17, e.MarginBounds.Y + 17);
                g.DrawString("Simulador de Colméia", arial24bold, Brushes.White,
                             e.MarginBounds.X + 15, e.MarginBounds.Y + 15);
            }

            int tableX        = e.MarginBounds.X + stringSize.Width + 50;
            int tableWidth    = e.MarginBounds.X + e.MarginBounds.Width - tableX - 20;
            int firstColumnX  = tableX + 2;
            int secondColumnX = tableX + (tableWidth / 2) + 5;
            int tableY        = e.MarginBounds.Y;

            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX, secondColumnX, tableY,
                                   "Abelhas", lblBees.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX, secondColumnX, tableY,
                                   "Flores", lblFlowers.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX, secondColumnX, tableY,
                                   "Mel na Colméia", lblHoneyInHive.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX, secondColumnX, tableY,
                                   "Néctar nas Flores", lblNectarInFlowers.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX, secondColumnX, tableY,
                                   "Quadros Transcorridos", lblFramesRun.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX, secondColumnX, tableY,
                                   "Taxa de Quadros", lblFrameRate.Text);
            g.DrawRectangle(Pens.Black, tableX, e.MarginBounds.Y, tableWidth, tableY - e.MarginBounds.Y);
            g.DrawLine(Pens.Black, secondColumnX, e.MarginBounds.Y, secondColumnX, tableY);

            using (var blackPen = new Pen(Brushes.Black, 2))
                using (var hiveBitmap = new Bitmap(_hiveForm.ClientSize.Width, _hiveForm.ClientSize.Height))
                    using (var fieldBitmap = new Bitmap(_fieldForm.ClientSize.Width, _fieldForm.ClientSize.Height))
                    {
                        using (var hiveGraphics = Graphics.FromImage(hiveBitmap))
                        {
                            _renderer.PaintHive(hiveGraphics);
                        }

                        int   hiveWidth  = e.MarginBounds.Width / 2;
                        float ratio      = hiveBitmap.Height / (float)hiveBitmap.Width;
                        int   hiveHeight = (int)(hiveWidth * ratio);
                        int   hiveX      = e.MarginBounds.X + ((e.MarginBounds.Width - hiveWidth) / 2);
                        int   hiveY      = e.MarginBounds.Height / 3;
                        g.DrawImage(hiveBitmap, hiveX, hiveY, hiveWidth, hiveHeight);
                        g.DrawRectangle(blackPen, hiveX, hiveY, hiveWidth, hiveHeight);
                        using (var fieldGraphics = Graphics.FromImage(fieldBitmap))
                        {
                            _renderer.PaintField(fieldGraphics);
                        }
                        int fieldWidth = e.MarginBounds.Width;
                        ratio = fieldBitmap.Height / (float)fieldBitmap.Width;
                        int fieldHeight = (int)(fieldWidth * ratio);
                        int fieldX      = e.MarginBounds.X;
                        int fieldY      = e.MarginBounds.Y + e.MarginBounds.Height - fieldHeight;
                        g.DrawImage(fieldBitmap, fieldX, fieldY, fieldWidth, fieldHeight);
                        g.DrawRectangle(blackPen, fieldX, fieldY, fieldWidth, fieldHeight);
                    }
        }
예제 #2
0
        private void document_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            Size stringSize;

            using (Font arial24bold = new Font("Arial", 24, FontStyle.Bold))
            {
                stringSize = Size.Ceiling(
                    g.MeasureString("Bee Simulator", arial24bold));
                g.FillEllipse(Brushes.Gray,
                              new Rectangle(e.MarginBounds.X + 2, e.MarginBounds.Y + 2,
                                            stringSize.Width + 30, stringSize.Height + 30));
                g.FillEllipse(Brushes.Black,
                              new Rectangle(e.MarginBounds.X, e.MarginBounds.Y,
                                            stringSize.Width + 30, stringSize.Height + 30));
                g.DrawString("Bee Simulator", arial24bold,
                             Brushes.Gray, e.MarginBounds.X + 17, e.MarginBounds.Y + 17);
                g.DrawString("Bee Simulator", arial24bold,
                             Brushes.White, e.MarginBounds.X + 15, e.MarginBounds.Y + 15);
            }

            int tableX        = e.MarginBounds.X + (int)stringSize.Width + 50;
            int tableWidth    = e.MarginBounds.X + e.MarginBounds.Width - tableX - 20;
            int firstColumnX  = tableX + 2;
            int secondColumnX = tableX + (tableWidth / 2) + 5;
            int tableY        = e.MarginBounds.Y;

            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX,
                                   secondColumnX, tableY, "Bees", Bees.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX,
                                   secondColumnX, tableY, "Flowers", Flowers.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX,
                                   secondColumnX, tableY, "Honey in Hive", HoneyInHive.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX,
                                   secondColumnX, tableY, "Nectar in Flowers", NectarInFlowers.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX,
                                   secondColumnX, tableY, "Frames Run", FramesRun.Text);
            tableY = PrintTableRow(g, tableX, tableWidth, firstColumnX,
                                   secondColumnX, tableY, "Frame Rate", FrameRate.Text);

            g.DrawRectangle(Pens.Black, tableX, e.MarginBounds.Y,
                            tableWidth, tableY - e.MarginBounds.Y);
            g.DrawLine(Pens.Black, secondColumnX, e.MarginBounds.Y,
                       secondColumnX, tableY);

            using (Pen blackPen = new Pen(Brushes.Black, 2))
                using (Bitmap hiveBitmap = new Bitmap(hiveForm.ClientSize.Width,
                                                      hiveForm.ClientSize.Height))
                    using (Bitmap fieldBitmap = new Bitmap(fieldForm.ClientSize.Width,
                                                           fieldForm.ClientSize.Height))
                    {
                        using (Graphics hiveGraphics = Graphics.FromImage(hiveBitmap))
                        {
                            renderer.PaintHive(hiveGraphics);
                        }

                        int   hiveWidth  = e.MarginBounds.Width / 2;
                        float ratio      = (float)hiveBitmap.Height / (float)hiveBitmap.Width;
                        int   hiveHeight = (int)(hiveWidth * ratio);
                        int   hiveX      = e.MarginBounds.X + (e.MarginBounds.Width - hiveWidth) / 2;
                        int   hiveY      = e.MarginBounds.Height / 3;
                        g.DrawImage(hiveBitmap, hiveX, hiveY, hiveWidth, hiveHeight);
                        g.DrawRectangle(blackPen, hiveX, hiveY, hiveWidth, hiveHeight);

                        using (Graphics fieldGraphics = Graphics.FromImage(fieldBitmap))
                        {
                            renderer.PaintField(fieldGraphics);
                        }
                        int fieldWidth = e.MarginBounds.Width;
                        ratio = (float)fieldBitmap.Height / (float)fieldBitmap.Width;
                        int fieldHeight = (int)(fieldWidth * ratio);
                        int fieldX      = e.MarginBounds.X;
                        int fieldY      = e.MarginBounds.Y + e.MarginBounds.Height - fieldHeight;
                        g.DrawImage(fieldBitmap, fieldX, fieldY, fieldWidth, fieldHeight);
                        g.DrawRectangle(blackPen, fieldX, fieldY, fieldWidth, fieldHeight);
                    }
        }