Fun WPF Second bullet: Electronic table font + display system time

Source: Internet
Author: User

Effect is such an effect, the difficulty compared to the previous article is also a lot simpler.

The first is to define a TextBlock as follows.

<Grid>     <TextBlock Name="tBlockTime" HorizontalAlignment="Center"          VerticalAlignment="Center" FontSize="68" Foreground="Green"/></Grid>

The background code is as follows:

Private DispatcherTimer DispatcherTimer;Public MainWindow () {InitializeComponent ();DispatcherTimer = new System. Windows. Threading. DispatcherTimer();Events that occur when the interval is over DispatcherTimer. Tick+ = new EventHandler (showcurrenttime);DispatcherTimer. Interval= New TimeSpan (0,0,0,1);DispatcherTimer. Start();}public void Showcurrenttime (object sender, EventArgs e) {//Get week//this. Tblocktime. Text= DateTime. now. ToString("dddd", the new System. Globalization. CultureInfo("ZH-CN"));This. Tblocktime. Text+="\ n";Acquired date//this. Tblocktime. Text= DateTime. now. ToString("Yyyy:MM:dd"); yyyy mm month DD DayThis. Tblocktime. Text+="\ n";Get the time division seconds this. Tblocktime. Text= DateTime. now. ToString("HH:mm:ss");}

Note at this time of the setting, the first step shows the time is "=", followed by "+ =". For example, to show the week first, and then show the seconds and minutes, that is:

//Get week This.tBlockTime   = Datetime  ( "dddd" , new System  ( "ZH-CN" ))  This.tblocktime   + =  ;  Get This.tblocktime   + = Datetime  ( "HH:mm:ss" )   

Then you need the font, but the font is not likely to be written ... We all need to reference resources.

<Window x:class="Wpfapplication2.mainwindow"        xmlns="Http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow"        Width="a" Height=" the"        WindowStyle="None"        allowstransparency="True"        Background="Black">    <window.resources>        <Style x:key="Quartzmsfont"><Setter property = "textelement. FontFamily" Value="Resources/#Quartz MS"/></Style>    </window.resources>    <Grid>        <TextBlock Name="Tblocktime" Style="{DynamicResource Quartzmsfont} "horizontalalignment=" center "verticalalignment=" center " FontSize =" Foreground" ="Green"/>                                             </Grid></Window>

Here I just give everyone an inspiration, if the system comes with the font has not been able to meet your artistic sense, you can completely find another font. You can even create fonts, which are being done by Google Apple recently.

I have put the font in the project, need the source/font of children's shoes directly to leave the mailbox ...

This is not a lot of content, but also not wonderful, but children's shoes can look at the previous article: Fun WPF First play: Window Jitter + border Shadow effect + countdown display text, you can also come to see the third article tomorrow ~

Thank you for your visit and hope to help you. We welcome your attention, collection and comment.

To make this article get treatise and ask questions, reprint please indicate the source:
Http://blog.csdn.net/nomasp

Fun WPF Second bullet: Electronic table font + display system time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.