[英]Thin-border on WPF window?
I'd like to create a window, using WPF, that has a thin border all the way around the form - ie no space for the title bar with the icon/caption and min/max/close buttons. 我想使用WPF创建一个窗口,该窗口在窗体周围始终有一个细边框-即标题栏没有空间,带有图标/标题和最小/最大/关闭按钮。 For example, the "extra" icons form of the new Windows 7 taskbar:
例如,新的Windows 7任务栏的“额外”图标形式:
Example Image http://img576.imageshack.us/img576/6196/border.png 范例图片http://img576.imageshack.us/img576/6196/border.png
I understand this can be done by setting the WindowStyle = None
property, however, I am also using the DwmExtendFrameIntoClientArea
API, which requires that the Background
property be transparent. 我知道可以通过设置
WindowStyle = None
属性来完成此操作,但是,我还使用了DwmExtendFrameIntoClientArea
API,该API要求Background
属性必须透明。 If I do this neither the window nor border are drawn, and only non-transparent controls on the form are drawn. 如果执行此操作,则不会绘制窗口和边框,并且只会绘制窗体上的非透明控件。
How can I achieve the thin border, whilst maintaining an Aero Glass effect on the main body of the form? 如何在边框上保持Aero Glass效果的同时实现细边框?
Use WindowStyle="None"
on the Window. 在窗口上使用
WindowStyle="None"
。 See MSDN for details . 有关详细信息,请参见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>
What you need to do is set ResizeMode=CanResize
and then do the following in the code behind: 您需要设置
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.