Oleg Oleg - 1 year ago 229
C# Question

Windows UI Automation: click tray icon button

I'd like to find and click tray icon button (Windows 10).
Helpers were took from here:

All works fine, but when application clicks button with name "Dropbox" really it clicks
another button with name "OneDrive" which is in tray area too:

foreach (var icon in EnumNotificationIcons())
var name = icon.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;
if (name.StartsWith("Dropbox"))

What is wrong?

This machine has 2 monitors.
I have tested on another computer winth win7 and 1 monitor - it works.


I have ran my application on 3 machines with different DPI settings. On all of these machines I installed target app. Naturally, the icon location should not be the same, but it seems I the the reason why tray button.Invoke in my app does not work: that in case of DPI!=100%

There are results:

1.100% - my app works ok.

Click =1741,x=1000


BoundingRectangle: l:1741 t:1000,Width=40,Height=40

BoundingRectangle: {l:1741 t:1000 r:1781 b:1040}

2.150% - my app does not work


BoundingRectangle: {l:3606 t:2040 r:3666 b:2100}

3.175% - my app does not work

BoundingRectangle: l:1977,t:1214,Width=70,Height=70

BoundingRectangle: {l:3460 t:2020 r:3530 b:2090}

How to solve the original task : how to click the icon in any case of DPI settings?

Answer Source

Solved, the answer is here: the reason is DPI. UI Automation works incorrect if DPI != 96. Need to add manifest code or app code as described here

How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download