本文实例为大家分享了C#实现简单的窗口抖动的具体代码,供大家参考,具体内容如下
属性赋值:
1、查看属性的类型,如果是C#中预定义的15种属性类型,直接赋值
(1)查看属性类型:鼠标悬停在属性单词上;
(2)C#中预定义的属性类型
2、排除第一种,符号后面试着敲空格,如果出现智能提示直接敲小数点,选择一个合适的选项分号结束
3、遇到特殊类型Color,等号后面直接使用属性类型单词点,选择一个分号结束
简单的窗口抖动案例
项目分析
1、首先添加窗口加载(load)事件,页面加载时设置窗口的大小,初始位置,在视图的工具箱中给窗口添加按钮(button);并设置button对象的text属性的属性值.
2、给button对象设置单击(click)事件;
3、改变窗口的位置(设置线程);
4、设置for循环,点击时执行多次;
5、添加随机色(背景)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
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)); } } } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/a_lllll/article/details/85243625