Exemple #1
0
        public static void RenderToGif(this Control control, Generator generator, string path, int secondsToPlay)
        {
            System.Windows.Forms.UserControl controlContainer = new System.Windows.Forms.UserControl();

            AnimatedGifEncoder e = new AnimatedGifEncoder();

            e.Start(path);
            e.SetDelay(50);
            e.SetRepeat(0);

            controlContainer.Width  = 400;
            controlContainer.Height = 400;
            var element = new ElementHost()
            {
                Child = control, Dock = System.Windows.Forms.DockStyle.Fill
            };

            controlContainer.Controls.Add(element);
            IntPtr handle = controlContainer.Handle;

            while (generator.CurrentTime < secondsToPlay)
            {
                RenderTargetBitmap bmp = new RenderTargetBitmap(controlContainer.Width, controlContainer.Height, 96, 96, PixelFormats.Pbgra32);
                bmp.Render(control);

                MemoryStream  stream  = new MemoryStream();
                BitmapEncoder encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));
                encoder.Save(stream);

                e.AddFrame(new Bitmap(stream));
                generator.PerformOneStep();
                System.Diagnostics.Debug.WriteLine("QUI " + generator.CurrentTime);
                Application.Current.Dispatcher.Invoke(
                    DispatcherPriority.Background,
                    new Action(() =>
                {
                    System.Diagnostics.Debug.WriteLine("Start refresh");
                    controlContainer.Refresh();
                    System.Diagnostics.Debug.WriteLine("End refresh");
                }));
                Thread.Sleep(10);
            }
            e.Finish();
            controlContainer.Dispose();
        }
Exemple #2
0
        private void titlebar_MouseDown(object sender, MouseEventArgs e)
        {
            if (Shiftorium.UpgradeInstalled("draggable_windows") && isInDrag == true)
            {
                var element = sender as FrameworkElement;
                currentPoint = e.GetPosition(null);

                transform.X         += (currentPoint.X - anchorPoint.X);
                transform.Y         += (currentPoint.Y - anchorPoint.Y);
                this.RenderTransform = transform;
                anchorPoint          = currentPoint;
                if (_isWPF == false)
                {
                    _wParent.Refresh();
                    (pgcontents.Content as WindowsFormsHost).InvalidateVisual();
                }
            }
        }