[英]Thin-border on WPF window?
我想使用WPF创建一个窗口,该窗口在窗体周围始终有一个细边框-即标题栏没有空间,带有图标/标题和最小/最大/关闭按钮。 例如,新的Windows 7任务栏的“额外”图标形式:
范例图片http://img576.imageshack.us/img576/6196/border.png
我知道可以通过设置WindowStyle = None
属性来完成此操作,但是,我还使用了DwmExtendFrameIntoClientArea
API,该API要求Background
属性必须透明。 如果执行此操作,则不会绘制窗口和边框,并且只会绘制窗体上的非透明控件。
如何在边框上保持Aero Glass效果的同时实现细边框?
在窗口上使用WindowStyle="None"
。 有关详细信息,请参见MSDN 。
<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>
您需要设置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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.