首页 > 编程知识 正文

android自定义组合控件,excel日期控件怎么设置

时间:2023-05-03 22:03:55 阅读:44984 作者:3439

WPF自定义日期和时间控制1、需求分析2、功能实现

一.需求分析

在工作中遇到的项目中,大多数软件都是全屏运行的。 在这种情况下,必须将日期和时间添加到软件界面中,以便用户可以查看当前时间。

二、功能这里的实现方法也很简单,大致定制一个控件,然后加文本框显示时间信息,后台通过定时器,定时获取系统时间,显示在文本框中。

1、创建自定义控件

在项目中创建新的用户控件并添加文本框。 在这里添加了与年月日、星期、时间对应的3个

user control x : class=' button demo.control.my time ' xmlns=' http://schemas.Microsoft.com/winfx/2006/xaml/presentation ' xmlns : x=' http://方案. Microsoft.com/winfx/2006/xaml ' xmlns 3360 MC=' http://schemas.openxmlflff 2006 ' xmlns : d=' http://schemas.Microsoft.com/expression/blend/2008 ' xmlns : local=' clr-namespace : button demo.control ' MC : ignorable=' d ' d 3360 designheight=' 60 ' d 3360 垂直对齐=' center ' horizontal alignment=' center ' text block x 330 foreground=' white ' fontsize=' 26 ' font weigggind text block x : name=' TB week ' text='星期三' margin='10, 0 ' foreground=' white ' fontsize=' 24 ' font weight=' bold '/text block x : name=' TB time ' text=' 0336051336000000

在这里添加计时器,用计时器获取每秒系统的时间,然后格式化并显示在界面上就可以了。 没有在此添加自定义特性。 就这样简单粗暴地使用就行了。 如果需要,可以自行定义字体颜色、字体大小等属性

publicpartialclassmytime :用户控制{ public my time (} { initialize component ) }; } dispatchertimerfreshdatetimetimer=newdispatchertimer (; //计时器privatevoidusercontrol _ loaded (对象发送器,布线事件) freshdatetimetimer.tick=freshdatetimetimer _ freshdatetimetimer_tick(null,null ); freshDateTimeTimer.Start (; } privatevoidfreshdatetimetimer _ tick (对象发送器,事件e ) { DateTime dt=DateTime.Now; XT time.text=dt.tostring (hh : mm : ss ); txtdate.text=dt.tostring (yyyy-mm-DD ); xtweek.text=dt.tostring('dddd ); }3、测试

如果将预定义的控件添加到主界面并手动生成解决方案,则可以看到控件可以正常使用

网格背景=' # 333 ' my : my time//grid的最终效果如下:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。