【发布时间】:2019-02-05 07:57:32
【问题描述】:
我正在尝试从 WPF 应用程序获取 Windows 任务栏的高度。我得到了这个How do I get the taskbar's position and size?,它显示了如何找到任务栏位置而不是高度。我得到了how can i get the height of the windows Taskbar? 的答复,上面写着
使用 Screen 类。任务栏是其 Bounds 和 WorkingArea 属性的区别。
但没有代码示例。如果这是正确的,这应该是任务栏的高度。我做得对吗?
private int WindowsTaskBarHeight => Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;
【问题讨论】:
-
为什么要获取任务栏高度?听起来您实际上想要实现不同的目标
-
您确定任务栏没有设置为自动隐藏吗?
-
@preciousbetine 不确定。
-
@DenisSchaf 实际上我需要这个来解决与 UI 相关的问题。
-
这仅适用于 PrimaryScreen。如果您想要任何屏幕的大小,那么:stackoverflow.com/a/2118993/891715 如果您唯一关心的是 PrimaryScreen,您可以使用 System.Windows.SystemParameters.PrimaryScreenWidth(因此您不必添加对 System.Windows.Forms 的引用)。此外,用户可以将任务栏放在一边...