似乎可以通过将窗口样式设置为None并使AllowTransparency=true来实现没有WinForm边框的表单样式。 但是,如果AllowTransparency=true的话,WPF的性能会大幅下降,视频会变得模糊。 没办法关闭;
仅将窗口样式设置为None似乎无法获得理想的结果。 还是有条框框的:
我以为可以马上通过API更改表单样式: SetWindowLong
在网上查了一下资料,发现去除WS_CATION=0x00C00000L似乎也没有效果。 看别人的文章,找到了WS_CATION=0x00C0000L。
因为两个值不同,所以全部使用。 setwindowlong(hwnd,GWL_STYLE,oldstyle(~)0x00c00000L|0x00c0000L ) )
终于成功了
真正的无边表单需要这样的效果,因为公司在制作触摸屏程序。
修改了wziyx513225244文章中封装的类。 http://blog.csdn.net/wziyx 513225244/article/details/6988494
用一个函数设定样式就可以了。 感谢wziyx513225244。
我相信很多人应该会遇到这个问题,所以给大家贴上:
公共群集方法
{
///summary
//带有边框和标题的windows样式
////summary
publicconstlongws _ caption=0x00c 00000 l;
publicconstlongws _ caption _2=0x00c 0000 l;
//publicconstlongws _ border=0x 0080000 l;
///summary
///窗口扩展样式层次视图
////summary
publicconstlongws _ ex _ layered=0x 00080000 l;
publicconstlongws _ child=0x 40000000 l;
///summary
//带阿尔法的样式
////summary
publicconstlonglwa _ alpha=0x 0000002 l;
///summary
//颜色设定
////summary
publicconstlonglwa _ color key=0x 00000001 l;
///summary
///窗口的基本样式
////summary
公共常数int gwl _ style=-16;
///summary
///窗口的扩展样式
////summary
公共常数int gwl _ ex style=-20;
///summary
//设置表单样式
////summary
///paramname='handle '操作表单的句柄/param
在///paramname='oldStyle '中设置表单的样式类型./param
/// <param name="newStyle">新样式</param>
[System.Runtime.InteropServices.DllImport( "User32.dll")]
public static extern void SetWindowLong(IntPtr handle, int oldStyle, long newStyle);
/// <summary>
/// 获取窗体指定的样式.
/// </summary>
/// <param name="handle">操作窗体的句柄</param>
/// <param name="style">要进行返回的样式</param>
/// <returns>当前window的样式</returns>
[System.Runtime.InteropServices.DllImport( "User32.dll")]
public static extern long GetWindowLong(IntPtr handle, int style);
/// <summary>
/// 设置窗体的工作区域.
/// </summary>
/// <param name="handle">操作窗体的句柄.</param>
/// <param name="handleRegion">操作窗体区域的句柄.</param>
/// <param name="regraw">if set to <c>true</c> [regraw].</param>
/// <returns>返回值</returns>
[System.Runtime.InteropServices.DllImport( "User32.dll")]
public static extern int SetWindowRgn(IntPtr handle, IntPtr handleRegion, bool regraw);
/// <summary>
/// 创建带有圆角的区域.
/// </summary>
/// <param name="x1">左上角坐标的X值.</param>
/// <param name="y1">左上角坐标的Y值.</param>
/// <param name="x2">右下角坐标的X值.</param>
/// <param name="y2">右下角坐标的Y值.</param>
/// <param name="width">圆角椭圆的width.</param>
/// <param name="height">圆角椭圆的height.</param>
/// <returns>hRgn的句柄</returns>
[System.Runtime.InteropServices.DllImport( "gdi32.dll")]
public static extern IntPtr CreateRoundRectRgn( int x1, int y1, int x2, int y2, int width, int height);
/// <summary>
/// Sets the layered window attributes.
/// </summary>
/// <param name="handle">要进行操作的窗口句柄</param>
/// <param name="colorKey">RGB的值</param>
/// <param name="alpha">Alpha的值,透明度</param>
/// <param name="flags">附带参数</param>
/// <returns>true or false</returns>
[System.Runtime.InteropServices.DllImport( "User32.dll")]
public static extern bool SetLayeredWindowAttributes(IntPtr handle, ulong colorKey, byte alpha, long flags);
//=================================================================================
/// <summary>
/// 设置窗体为无边框风格
/// </summary>
/// <param name="hWnd"></param>
public static void SetWindowNoBorder(IntPtr hWnd)
{
long oldstyle = NativeMethods.GetWindowLong(hWnd, NativeMethods.GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, oldstyle & (~(WS_CAPTION | WS_CAPTION_2)));
//SetWindowLong(hWnd, GWL_EXSTYLE, WS_CHILD);
}
}
本文来自detecyang的博客,原文地址:http://blog.csdn.net/detecyang/article/details/7946237