C#实现简单的窗口抖动
本文实例为大家分享了C#实现简单的窗口抖动的具体代码,供大家参考,具体内容如下
属性赋值:
1、查看属性的类型,如果是C#中预定义的15种属性类型,直接赋值
(1)查看属性类型:鼠标悬停在属性单词上;
(2)C#中预定义的属性类型
2、排除第一种,符号后面试着敲空格,如果出现智能提示直接敲小数点,选择一个合适的选项分号结束
3、遇到特殊类型Color,等号后面直接使用属性类型单词点,选择一个分号结束
简单的窗口抖动案例
项目分析
1、首先添加窗口加载(load)事件,页面加载时设置窗口的大小,初始位置,在视图的工具箱中给窗口添加按钮(button);并设置button对象的text属性的属性值.
2、给button对象设置单击(click)事件;
3、改变窗口的位置(设置线程);
4、设置for循环,点击时执行多次;
5、添加随机色(背景)
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Windows.Forms;
//全部都是命名空间
usingSystem.Threading;
namespace_02窗口抖动
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
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;
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
//设置随机色
Randomr=newRandom();
for(inti=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));
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。