zoukankan      html  css  js  c++  java
  • RectAnimation用于在DrawingVisual画进度条

    使用Visual来画图,可以使用其派生类,UIElement、Viewport3DVisual用于呈现3D内容,其他可以用来画图的为DrawingVisual,使用DrawingVisual可以使用编程的方式来实现复杂的图形实现,当使用DrawingVisual,必须使用FrameworkElement作为宿主容器,用来提供DrawingVisual所缺乏的布局和事件支持。下面实现了使用DrawingVisual来实现进度条,主要使用RectAnimation来实现。DrawRoundedRectangle(Brush brush, Pen pen, Rect rectangle, AnimationClock rectangleAnimations, double radiusX, AnimationClock radiusXAnimations, double radiusY, AnimationClock radiusYAnimations)方法的使用RectAnimation对象的AnimationClock对 Rec进行动画处理。

            RectAnimation myRectAnimation;
            public override System.Windows.Media.Visual drawShape()
            {
                    DrawingVisual drawingWordsVisual = new DrawingVisual();
                    DrawingContext drawingContext = drawingWordsVisual.RenderOpen();
                    try
                    {
                            Rect rect2 = new Rect(currentLayout.StartPoint.X,
                            currentLayout.StartPoint.Y, VisusalSize.Width, 3);
                            Rect rect3 = new Rect(currentLayout.StartPoint.X, 
                            currentLayout.StartPoint.Y, VisusalSize.Width, 3);
                            
                            Rect rect1 = new Rect(currentLayout.StartPoint.X, currentLayout.StartPoint.Y, 0, 3);
                            //Rect rect4 = new Rect(currentLayout.StartPoint.X, currentLayout.StartPoint.Y, VisusalSize.Width*0.5, 0);
    
                            myRectAnimation = new RectAnimation();
    
                            myRectAnimation.Duration = TimeSpan.FromSeconds(10);
                            myRectAnimation.FillBehavior = FillBehavior.HoldEnd;
    
                            myRectAnimation.From = rect1;
                            //myRectAnimation.By = rect4;
                            myRectAnimation.To = rect3;
    
                            _showFilePanelClock = myRectAnimation.CreateClock();
    
                            _showFilePanelClock.Controller.Pause();
    
                            GradientStop gs1 = new GradientStop(Color.FromRgb(49, 158, 
                            222), 1);
                            GradientStop gs2 = new GradientStop(Color.FromRgb(69, 182, 
                            233), 1);
                            GradientStopCollection gsc = new GradientStopCollection();
                            gsc.Add(gs1);
                            gsc.Add(gs2);
                            Brush colorbrush = new LinearGradientBrush(gsc,
                             new Point(0, 1), new Point(0, 0.8));
                            Brush solidBrush = new SolidColorBrush(Color.FromRgb(203, 
                            203, 203));
                            drawingContext.DrawRectangle(solidBrush, new Pen(), rect2);
                            drawingContext.DrawRoundedRectangle(colorbrush, new Pen(),
                            rect1, _showFilePanelClock, 2, null, 2, null);
                    }
                    catch (Exception ex)
                    {
                            new SaveExceptionInfo().SaveLogAsTXTInfoex(ex.Message);
                    }
                    finally
                    {
                            drawingContext.Close();
                    }
                    return drawingWordsVisual;
            }

    使用下面的方法来控制进度条的进度,根据要显示的百分比,使用ClockController.Seek来控制进度条的进度。

    public void FilesavedSize_saveSizeChanged(object sender, SendFileEventArgs args)
            {
                 double percent = double.Parse(args.SavedSize.ToString())
                 / double.Parse(args.FileSize.ToString());
                 TimeSpan timeSpan = TimeSpan.FromMilliseconds(percent * 10000);
                 _showFilePanelClock.Controller.Seek(timeSpan,
                  TimeSeekOrigin.BeginTime);
                 _showFilePanelClock.Controller.Pause();
            }
  • 相关阅读:
    TP5 try{}catch{}异常捕获不到 解决办法
    layui2.5 开关在confirm确认了之后在关/开
    JQuery 表单textarea控制字数
    Navicat Premium从远程Mysql数据库复制到本地数据库的方法
    dedecmsV5.7 任意文件上传漏洞修复
    PHP 利用PHPExcel到处数据到Excel;还有导出数据乱码的解决方案。
    Mac Pro 2017款自带php与用brew重装PHP后的地址
    用js传递当前页面的url,丢失了&后面的参数 解决办法
    PHP 超全局变量之$_SERVER
    Linux while和for循环简单分析
  • 原文地址:https://www.cnblogs.com/goxmpx/p/3759911.html
Copyright © 2011-2022 走看看