[英]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.