C#实现简单的窗口抖动

本文实例为大家分享了C#实现简单的窗口抖动的具体代码,供大家参考,具体内容如下

属性赋值:

1、查看属性的类型,如果是C#中预定义的15种属性类型,直接赋值
(1)查看属性类型:鼠标悬停在属性单词上;
(2)C#中预定义的属性类型
2、排除第一种,符号后面试着敲空格,如果出现智能提示直接敲小数点,选择一个合适的选项分号结束
3、遇到特殊类型Color,等号后面直接使用属性类型单词点,选择一个分号结束
简单的窗口抖动案例

项目分析
1、首先添加窗口加载(load)事件,页面加载时设置窗口的大小,初始位置,在视图的工具箱中给窗口添加按钮(button);并设置button对象的text属性的属性值.
2、给button对象设置单击(click)事件;
3、改变窗口的位置(设置线程);
4、设置for循环,点击时执行多次;
5、添加随机色(背景)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//全部都是命名空间
using System.Threading;
 
namespace _02窗口抖动
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
      this.BackColor = Color.Pink;
      //设置窗口的大小
      this.Width = 300;
      this.Height = 300;
      //窗口初识位置
      this.Left = 300;
      this.Top = 300;
      //button按钮设置文本为“按钮”
      button1.Text = "按钮";
      button1.Width = 80;
      button1.Height = 40;
      button1.BackColor = Color.SkyBlue;
    }
 
    private void button1_Click(object sender, EventArgs e)
    {
     //设置随机色
      Random r = new Random();
      for (int i=0;i<5;i++) {
        //this.BackColor = Color.Plum;
        this.Left = 303;
        //线程:代码执行的路线进程
        //方法:小括号分号结束,给括号中填参数
        Thread.Sleep(20);
        this.Top = 303;
        Thread.Sleep(20);
        //this.BackColor = Color.Tomato;
        this.Left = 300;
        Thread.Sleep(20);
        this.Left = 297;
        Thread.Sleep(20);
        this.Top = 300;
        Thread.Sleep(20);
        this.Top = 297;
        Thread.Sleep(20);
        //this.BackColor = Color.SteelBlue;
        this.Left = 300;
        Thread.Sleep(20);
        this.Left = 307;
        Thread.Sleep(20);
        this.Top = 300;
        Thread.Sleep(20);
        this.Left = 300;
        //this.BackColor = Color.Pink;
      }
      //随机色
      this.BackColor = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256));
    }
  }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//全部都是命名空间
using System.Threading;

namespace _02窗口抖动
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
      this.BackColor = Color.Pink;
      //设置窗口的大小
      this.Width = 300;
      this.Height = 300;
      //窗口初识位置
      this.Left = 300;
      this.Top = 300;
      //button按钮设置文本为“按钮”
      button1.Text = "按钮";
      button1.Width = 80;
      button1.Height = 40;
      button1.BackColor = Color.SkyBlue;
    }

    private void button1_Click(object sender, EventArgs e)
    {
     //设置随机色
      Random r = new Random();
      for (int i=0;i<5;i++) {
        //this.BackColor = Color.Plum;
        this.Left = 303;
        //线程:代码执行的路线进程
        //方法:小括号分号结束,给括号中填参数
        Thread.Sleep(20);
        this.Top = 303;
        Thread.Sleep(20);
        //this.BackColor = Color.Tomato;
        this.Left = 300;
        Thread.Sleep(20);
        this.Left = 297;
        Thread.Sleep(20);
        this.Top = 300;
        Thread.Sleep(20);
        this.Top = 297;
        Thread.Sleep(20);
        //this.BackColor = Color.SteelBlue;
        this.Left = 300;
        Thread.Sleep(20);
        this.Left = 307;
        Thread.Sleep(20);
        this.Top = 300;
        Thread.Sleep(20);
        this.Left = 300;
        //this.BackColor = Color.Pink;
      }
      //随机色
      this.BackColor = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256));
    }
  }
}

以上就是本文的全部内容,希望vb.net教程对大家的学习有所帮助,也希望大家多多支持

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值