Search code examples
c#system.drawingtaskbar

Draw on Windows taskbar in C#


I want to make a binary clock for Windows. But I want it to replace the default clock (having 2 clocks is unoptimal).

So one of the approaches is just to draw my binary clock on top of the old one. How do I do that? Using external libraries is allowed.

I've tried sth like this:

    public Form1()
    {
        InitializeComponent();
        this.Paint += new PaintEventHandler(Form1_Paint);
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.FillEllipse(new SolidBrush(Color.Blue), new Rectangle(1500, 790, 20, 20));
    }

But it doesn't reach the taskbar (bottom right corner): ellipse not reaching taskbar

If it turns out to be impossible I'll make another question about deskbands. But for now I'm asking about drawing on Windows taskbar.


Solution

  • There are numerous things wrong with this approach.

    1. The taskbar exists as its own thing, separate from your application. You can't draw on it very easily, you need to go through the Windows SDK to interact with it (e.g. customize your application's flyout preview). Additionally, that would be a terrible idea if Windows allowed every application that wanted to draw on top of the taskbar to do so. Who wins if everyone's drawing?

    2. Even if you could draw on it, you would have to account for every single thing that it and its flyout window does. How wide is it? What happens if you click on the calendar? What if it's styled differently? What if there's more than one clock? Does the user even have rights to do things with the clock?

    3. There is no built-in way to replace the clock. Replacements do exist, but primarily by hooking the flyout window and doing what I listed in the 2nd option. See T-Clock as an example.

    You're much better off going a different route.