C#/Winform实现Win8MetroLoading动画

本文介绍了如何使用C#和GDI+在Winform中实现Win8 Metro风格的加载动画。作者分享了实现这一效果的源码,并提供了下载链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



非常喜欢Metro风格的界面,所以想模仿一下一些UI效果的实现,网上找到了很多,但都是CSS3,WPF等实现,对于XAML和CSS3一窍不通,无奈下只有自己开始写。

下面是源码:

LoadingCircle.cs

using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using ThreadingTimer = System.Threading.Timer;
using UITimer = System.Windows.Forms.Timer;

namespace LoadingCircle
{
    /// <summary>
    /// 表示一个加载圆圈动画
    /// </summary>
    [ToolboxBitmap(typeof (LoadingCircle), "LoadingCircleIcon.png")]
    public partial class LoadingCircle : UserControl
    {
        #region 构造

        public LoadingCircle()
        {
            InitializeComponent();

            //双缓冲,禁擦背景
            SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.OptimizedDoubleBuffer,
                true);

            //初始化绘图timer
            _graphicsTmr = new UITimer {Interval = 1};
            //Invalidate()强制重绘,绘图操作在OnPaint中实现
            _graphicsTmr.Tick += (sender1, e1) => Invalidate(false);

            _dotSize = Width/10f;

            //初始化"点"
            _dots = new Dot[5];

            Color = Color.White;
        }

        #endregion 构造

        #region 属性

        /// <summary>
        ///     圆心
        /// </summary>
        [Browsable(false)]
        public PointF CircleCenter
        {
            get { return new PointF(Width/2f, Height/2f); }
        }

        /// <summary>
        ///     半径
        /// </summary>
        [Browsable(false)]
        public float CircleRadius
        {
            get { return Width/2f - _dotSize; }
        }

        /// <summary>
        ///     颜色
        /// </summary>
        [Browsable(true), Category("Appearance"), Description("设置\"点\"的前景色")]
        public Color Color { get; set; }

        #endregion 属性

        #region 字段

        //点数组
        private readonly Dot[] _dots;

        //Timers
        private readonly UITimer _graphicsTmr;
        private ThreadingTimer _actionTmr;

        //点大小
        private float _dotSize;

        //是否活动
        
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值