码迷,mamicode.com
首页 > Windows程序 > 详细

RectAnimation用于在DrawingVisual画进度条

时间:2014-06-03 12:34:56      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

使用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进行动画处理。

bubuko.com,布布扣
        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;
        }
bubuko.com,布布扣

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

bubuko.com,布布扣
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();
        }
bubuko.com,布布扣

RectAnimation用于在DrawingVisual画进度条,布布扣,bubuko.com

RectAnimation用于在DrawingVisual画进度条

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/goxmpx/p/3759911.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!