WPF去边框与webbrowser的冲突
2016-04-25 15:13
906 查看
最近弄了弄WPF,最简单的,一个窗体,里面加个webbrowser
但是如果用AllowTransparency="True" WindowStyle="None"的话,的确窗体的边框和原生按钮去掉了
但是,webbrowser里打开的页面也看不见了
看了一圈网上的解决办法,基本上都是那个WebBrowserOverlay,真是个大坑,一点不好用
所以找到另一个办法,就是用SetWindowLong来解决,当然AllowTransparency跟WindowSytle都要去掉
首先建一个类,比如NativeMethods.cs
这样就完美实现了外窗口无原生按钮(最大最小关闭),无边框,一点边框都没有。
备忘用
当当当当当!
但是如果用AllowTransparency="True" WindowStyle="None"的话,的确窗体的边框和原生按钮去掉了
但是,webbrowser里打开的页面也看不见了
看了一圈网上的解决办法,基本上都是那个WebBrowserOverlay,真是个大坑,一点不好用
所以找到另一个办法,就是用SetWindowLong来解决,当然AllowTransparency跟WindowSytle都要去掉
首先建一个类,比如NativeMethods.cs
class NativeMethods{ public const int WS_CAPTION=0x00C0000; public const int WS_BORDER=0x00800000; public const int WS_DLGFRAME=0x00400000; public const int GWL_STYLE=-16; [DllImport("user32", EntryPoint="GetWindowLong")] public static extern int GetWindowLong(IntPtr handle, int sytle); [DllImport("user32", EntryPoint="SetWindowLong")] public static extern int SetWindowLong(IntPtr handle, int oldStyle, int new Style); }然后在你的窗体代码中,比如MainWindow.xaml.cs
public partial class MainWindow : Window{ IntPtr hwnd=new System.Windows.Interop.WindowInteropHelper(this).Handle; int oldStyle=NativeMethods.GetWindowLong(hwnd,NativeMethods.GWL_STYLE); NativeMethods.SetWindowLong(hwnd,NativeMethods.GWL_STYLE,oldStyle&~NativeMethods.WS_BORDER&~NativeMethods.WS_CAPTION&~NativeMethods.WS_DLGFRAME); } public MainWindow(){ InitializeComponent(); this.Loaded+=Window_Loaded; //窗体中的其它语句 }
这样就完美实现了外窗口无原生按钮(最大最小关闭),无边框,一点边框都没有。
备忘用
当当当当当!
相关文章推荐
- C#及WPF获取本机所有字体和颜色的方法
- 关于vbs WebBrowser导航问题
- WPF MVVM示例讲解
- WPF实现时钟特效
- PowerShell中调用WPF生成炫酷窗口实例
- C#中WebBroeser控件用法实例教程
- DIV border边框显示不完全问题的解决方法
- C#通过重写Panel改变边框颜色与宽度的方法
- C#使用webbrowser的常见用法实例
- WPF实现类似360安全卫士界面的程序源码分享
- C#实现Winform无边框移动的方法
- C#中WPF使用多线程调用窗体组件的方法
- C#的WebBrowser操作frame实例解析
- WPF实现渐变淡入淡出的登陆窗口效果
- C#之WinForm WebBrowser实用技巧汇总
- WinForm项目开发中WebBrowser用法实例汇总
- WPF的数据绑定详细介绍
- 纯CSS实现的漂亮的立体图片边框效果,阴影代码
- WPF绑定实例详解
- JS实现动态给图片添加边框的方法