首页 > 解决方案 > 适用于 Windows 10 的 C# 停靠代码栏

问题描述

我正在寻找一种占据窗口顶部 15% 并为用户显示消息(销售电话)的方法,我不希望用户能够调整大小或关闭它。

如果有人最大化另一个应用程序,我不希望它覆盖我们的代码。

标签: c#

解决方案


这只是 WPF 的一个示例:

<Window x:Class="Ticker.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="Ticker"
    Topmost="True"
    ResizeMode="NoResize"
    WindowStyle="None"
    WindowStartupLocation="Manual" 
    Left="0" 
    Top="0">
<Grid>

</Grid>

根据显示器的高度设置 15% 的高度:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        this.Height = (SystemParameters.PrimaryScreenHeight * 0.15);
        this.Width = SystemParameters.PrimaryScreenWidth;
    }
}

推荐阅读