Windows 10 has a nice date and time display in his taskbar, it is becoming more difficult for me to see , unless I open it. Becoming older and older my eyes are not that ‘fresh’ as they used to be, so I decided to make a bigger time display that stays permanently on top of the screen.
I’m not that proficient with WPF, but decided to give it a go and at last it worked! Try to do something you don’t fully understand and you will learn!

//Here is my code from the MainWindow.xaml file:
Window x:Class="TimerWindow.MainWindow"
        Title="Timer" Height="50" Width="350" WindowStyle="None" 
        AllowsTransparency="True" Background="Transparent" 
        MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseDoubleClick="Window_MouseDoubleClick" Loaded="Window_Loaded">

    <Grid >
        <Border CornerRadius="25" BorderBrush="Blue" BorderThickness="5" Background="LawnGreen"></Border>

            <Ellipse Height="50" Width="30" StrokeThickness="5" Stroke="Blue"  Fill="Gold" />

        <TextBox Name="TimeTxbx" Height="23" Width="180" Background="LawnGreen" BorderBrush="Blue" BorderThickness="2"
                 FontSize="16" FontWeight="Bold" TextAlignment="Center"></TextBox>

        <Ellipse Height="50" Width="30" StrokeThickness="5" Stroke="Blue" HorizontalAlignment="Right"  Fill="Gold"/>

//And this is the code from MainWindow.xaml.cs:
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;

namespace TimerWindow
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        private DispatcherTimer timer;

        public MainWindow()
            timer = new DispatcherTimer();
            timer.Tick += Timer_Tick;
            timer.Interval = new TimeSpan(1000); //tick every second

        private void Timer_Tick(object sender, EventArgs e)
            TimeTxbx.Text = DateTime.Now.ToString();

        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

        private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)

        private void Window_Loaded(object sender, RoutedEventArgs e)
            this.Topmost = true; //won't always work but is sufficient here
            MessageBox.Show("Hello I will show you a timer window after you click OK" + "\n" +
                "While clicking once you can drag it, doubleclicking will close the application", 
                "Info", MessageBoxButton.OK, MessageBoxImage.Information);

But I have a question: why is it that, when I remove the canvas tags from th first ellipse definition, if not it will appear under the textbox?

Here is how this window looks on screen:

Recommended Answers

All 2 Replies

No need to use canvas, h.alingment of ellipse should be left.

commented: Thank you for this info! +15

Thank you Shark_1 for solving my problem! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.