C# winform学习 Timer、Textbox、Button

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中显示出来
        }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一枚努力的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值