【问题标题】:Thin-border on WPF window?WPF窗口上的细边框?
【发布时间】:2010-05-24 20:45:54
【问题描述】:

我想使用 WPF 创建一个窗口,该窗口在表单周围一直有一个细边框 - 即没有空间用于带有图标/标题和最小/最大/关闭按钮的标题栏。例如,新的 Windows 7 任务栏的“额外”图标形式:

Example Image http://img576.imageshack.us/img576/6196/border.png

我知道这可以通过设置WindowStyle = None 属性来完成,但是,我也在使用DwmExtendFrameIntoClientArea API,它要求Background 属性是透明的。如果我这样做,既不绘制窗口也不绘制边框,只绘制窗体上的非透明控件。

如何实现细边框,同时在表单主体上保持 Aero Glass 效果?

【问题讨论】:

    标签: c# wpf windows


    【解决方案1】:

    在窗口上使用WindowStyle="None"See MSDN for details.

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="100" Width="100" WindowStyle="None">
         Hello World
    </Window>
    

    【讨论】:

    • 你也可以添加一个 元素来设置你需要的厚度
    • 我正在使用DwmExtendFrameIntoClientArea API 在整个表单上设置 Aero Glass 背景 - 设置 WindowStyle="None" 意味着只绘制表单的非透明部分(并且没有边框)。跨度>
    • WindowStyle="None" 将在窗口周围绘制一个边框,就像在您的屏幕截图中一样。
    • 只有当我没有将背景颜色设置为“透明”时才会得到那个边框(据我所知,这是DwmExtendFrameIntoClientArea 工作所必需的)。如果背景颜色设置为透明(不透明度仍为 1.0),则不绘制边框。
    【解决方案2】:

    你需要做的是设置ResizeMode=CanResize,然后在后面的代码中执行以下操作:

    protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr LParam, ref bool handled)
    {
        switch (msg)
        {
            case WM_NCHITTEST:
                        //if the mouse pointer is not over the client area of the tab
                        //ignore it - this disables resize on the glass chrome
                        //a value of 1 is the HTCLIENT enum value for the Client Area
                        if (DefWindowProc(hwnd, WM_NCHITTEST, wParam, LParam).ToInt32() == 1)
                        {
                            handled = true;
                        }
                        break;
         }
    }
    
    [DllImport("user32.dll")]
            public static extern IntPtr DefWindowProc(IntPtr hWnd, int uMsg, IntPtr wParam,
               IntPtr lParam);
    

    【讨论】:

      【解决方案3】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-31
        • 2011-03-23
        • 1970-01-01
        相关资源
        最近更新 更多