我可以将显示时间的标签转换为背景颜色吗? [英] can I convert a label that shows the time into a background color?

查看:118
本文介绍了我可以将显示时间的标签转换为背景颜色吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示时间的标签,我想将label.text转换为背景颜色,每次更改时更改。这可能吗?我的代码如下。
例如:
如果显示的时间是11:23:04,我想将背景颜色更改为#112304。
如果显示的时间是11:24:00,我想将背景颜色更改为#112400。
等等。

I have a label that displays the time and I would like to convert that label.text into a color for the background that changes every time the time changes. Is this possible? My code is below. Example: If the time displayed is 11:23:04 I would like the background color to be changed to #112304. If the time displayed is 11:24:00 I would like the background color to be changed to #112400. etc. etc.

Private Sub Timer1_Tick() Handles Timer1.Tick

    Label1.Text = TimeOfDay

    Label2.Text = System.DateTime.Now.ToString("MM/d/yyy")

End Sub


推荐答案

结合Dmandy的ColorTranslator.FromHtml ToString():

Combine Dmandy's ColorTranslator.FromHtml() approach and format the time as you've already demonstrated with ToString():

Me.BackColor = ColorTranslator.FromHtml(DateTime.Now.ToString("#HHmmss"))

这篇关于我可以将显示时间的标签转换为背景颜色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆