C# winform学习 Timer、Textbox、Button

来源:互联网 发布:杭州贰贰网络怎么样 编辑:程序博客网 时间:2024/05/18 13:10

MessageBox():   文本框

this.close()// 代表当前窗体结束

Button 

    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            MessageBox.Show ("真听话");            this.Close();        }        private void button2_Click(object sender, EventArgs e)        {            MessageBox.Show("不学习不是好孩子");            this.Close();        }        // 给按钮一个新的坐标        private void button2_MouseEnter(object sender, EventArgs e)          { // 给按钮一个随机坐标            int x = this.ClientSize.Width - button2.Width;            int y = this.ClientSize.Height - button2.Height;            Random r = new Random();            button1.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1));        }    }


Textbox

wordWrap:指示文本框是否自动换行

ScrolBars :是否显示滚动条

PasswordChar:  以密码的形式输入(单一字符)

label:用来显示文本

TextChanged:文本框发生变化时触发事件

lblText.Text=txtwords.Text;(拿到了txtwords中的内容)


组件:timer

在指定的时间间隔内做一件指定的事情。

Timer---->Tick: 每隔一定时间发生的事件

timer:指定事件发生的频率

datetime.Now,tostring();   // 获取当前的时间,转换成string

Load属性:窗体加载的时候发生的事件;双击窗体,出现load属性

闪烁字:

 

       private void timer1_Tick_1(object sender, EventArgs e)        {            string str=textBox1.Text ;           //选取第2个(下标为1的)之后的字符+第1个字符起选1个字符            textBox1.Text = str.Substring(1) + str.Substring(0, 1);        }
闹钟:


        private void timer2_Tick(object sender, EventArgs e)        {            label1.Text = DateTime.Now.ToString();   // 获得当前时间            if(DateTime .Now .Hour ==21&&DateTime .Now .Minute ==44&&DateTime .Now .Second ==32){   //到了设定的时间,闹钟响                SoundPlayer sound = new SoundPlayer();   // 命名空间为 using System.Media;                sound.SoundLocation = @"F:\C#\video\1.wav";  // 找到文件的地址                sound.Stop();            }        }

      private void Form1_Load(object sender, EventArgs e)        {            label1.Text = DateTime.Now.ToString();    // 当前的时间以字符串的形式放在label中显示出来        }

原创粉丝点击