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

C#制作闪动的窗体

时间:2014-12-11 22:30:54      阅读:369      评论:0      收藏:0      [点我收藏+]

标签:c#   闪动窗体   

C#制作闪动的窗体

        本文讲述如何使用C#创建闪动的窗体。
        新建Windows窗体应用程序,添加按钮点击事件。全部程序如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace _2_fun_with_if_else
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            while (Visible) // 关闭窗体时,停止循环
            {
                for (int c = 0; c < 254 && Visible; c++)
                {
                    this.BackColor = Color.FromArgb(c, 255 - c, c); // 此方法指定三个数字:red/green/blue.
                    Application.DoEvents(); // 此语句使操作系统能够在程序之外执行其他操作。否则
                    // 程序将占用所有CPU周期
                    Thread.Sleep(3); // 此语句在循环中插入3毫秒的延迟。
                }
                for (int c = 254; c >= 0 && Visible; c--)
                {
                    this.BackColor = Color.FromArgb(c, 255 - c, c);
                    Application.DoEvents();
                    Thread.Sleep(3);
                }
            }
        }
    }
}
        运行后效果如图:
bubuko.com,布布扣

C#制作闪动的窗体

标签:c#   闪动窗体   

原文地址:http://blog.csdn.net/crazygolf/article/details/41873787

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