Exemplo n.º 1
0
        public static void PrintWindow(Control control)
        {
            control.Refresh();
            System.Threading.Thread.Sleep(100);
            Bitmap      bmp = CScreenCopieur.GetWindowImage(control);
            PrintDialog dlg = new PrintDialog();

            dlg.PrinterSettings = new PrinterSettings();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                PrintDocument document = new PrintDocument();
                document.PrinterSettings = dlg.PrinterSettings;
                CScreenPrinter printer = new CScreenPrinter();
                printer.m_bitmapToPrint = bmp;
                document.PrintPage     += new PrintPageEventHandler(printer.document_PrintPage);
                document.Print();
            }
        }
Exemplo n.º 2
0
        /////////////////////////////////////////
        private void StartAnimate(Control control, EAnimationControl animation)
        {
            //Sauve le fond
            Bitmap bmpFond = CScreenCopieur.GetDesktopImage();
            //Copie l'image du contrôle
            Bitmap bmpControle = CScreenCopieur.GetWindowImage((Control)control);

            IntPtr   deskDC = GetDC(IntPtr.Zero);
            Graphics g      = Graphics.FromHdc(deskDC);

            Point     pt      = ((Control)control).Parent.PointToScreen(((Control)control).Location);
            Size      sz      = ((Control)control).Size;
            Rectangle maxRect = new Rectangle(0, 0, 0, 0);

            int nNbZoom = animation == EAnimationControl.Zoom ? 1 : 2;

            for (int nZoom = 0; nZoom < nNbZoom; nZoom++)
            {
                double fPas   = 6;
                double fSize  = 0;
                double fRatio = (double)sz.Height / (double)sz.Width;
                while (true)
                {
                    fSize += fPas;
                    if (fPas > 0)
                    {
                        fPas /= 1.1;
                        if (fPas < 0.1)
                        {
                            fPas = 0.1;
                        }
                    }
                    else
                    {
                        fPas *= 1.1;
                    }
                    double    fNewWidth    = (double)sz.Width + fSize;
                    double    fNewHeight   = (double)sz.Height + fSize * fRatio;
                    double    fEcartWidth  = (fNewWidth - sz.Width) / 2.0;
                    double    fEcartHeight = (fNewHeight - sz.Height) / 2.0;
                    Rectangle rct          = new Rectangle((int)(pt.X - fEcartWidth),
                                                           (int)(pt.Y - fEcartHeight),
                                                           (int)(sz.Width + fEcartWidth * 2),
                                                           (int)(sz.Height + fEcartHeight * 2));
                    g.DrawImage(bmpControle, rct);
                    if (rct.Width > maxRect.Width ||
                        rct.Height > maxRect.Height)
                    {
                        maxRect = rct;
                    }
                    if (fSize >= 25)
                    {
                        fPas = -fPas;
                    }
                    if (fSize < 1)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(2);
                    //maxRect.Inflate(4, 4);
                    g.DrawImage(bmpFond, maxRect, maxRect, GraphicsUnit.Pixel);
                }
                System.Threading.Thread.Sleep(2);
            }
            //Redessine le fond
            g.DrawImage(bmpFond, maxRect, maxRect, GraphicsUnit.Pixel);
            g.Dispose();
            bmpControle.Dispose();
            bmpFond.Dispose();
        }