Winform:RichTextBox插入字体编辑颜色、位置;计时器;当前时间显示

 1.RichTextBox插入字体编辑颜色,连接的数据库,读取数据库里的内容

public void nowperson()
        {
            now.Clear();  // 清除文本内容
            Dao dao = new Dao();
            string sql = "select top 1 * from dbo.Wait where Condition = '未完成' OR Condition = '置顶' order by Condition DESC,RealTime";
            IDataReader dc = dao.read(sql);
            while (dc.Read())
            {
                //now.BulletIndent = 30;//指定文本距离控件最左边缩进30个像素
                //now.SelectionBullet = true;  // 指定后面插入的文本开始进行缩进
                now.SelectionFont = new Font("楷体", 60);//设置当前插入文本为楷体60号字体
                now.SelectionColor = Color.Red;  // 设定插入文本的颜色
                now.SelectionAlignment = HorizontalAlignment.Center;  //设置文本居中
                now.SelectedText =  dc[1].ToString() + "\t";  // 插入的文本内容,空格

                now.SelectionFont = new Font("楷体", 72);//设置当前插入文本楷体72号字体               
                now.SelectionColor = Color.Red;  // 设定插入文本的颜色
                now.SelectedText = dc[2].ToString() + "\n";  // 插入的文本内容,换行

                //now.SelectionBullet = false;//关闭缩进
                //now.SelectionFont = new Font("Verdana", 10);//重新设定字体
                //now.SelectedText = "The bulleted text is indented 30 pixels from the bullet symbol using the BulletIndent property.\n";//插入文本            
            }

            dc.Close();
            dao.DaoClose();
        }

 2.计时器

用到了一个组件Timer,用于定时刷新等

需要工作时Enabled设置为true

Interval为刷新频率,单位为毫秒,1000ms为1s

之后双击把需要定时刷新的内容放入即可 

 

 private void timer1_Tick(object sender, EventArgs e)
        {
            nowperson();
            allpeople();
        }

3.当前时间显示

也是计时器的用法,拖入timer添加事件即可,拖入label作为显示的容器

        private void showtime_Tick(object sender, EventArgs e)
        {
            label3.Text = DateTime.Now.ToString();
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值