WPF去边框与webbrowser的冲突

发布时间:2020-07-16 13:34:12 作者:lreach
来源:网络 阅读:1692

最近弄了弄WPF,最简单的,一个窗体,里面加个webbrowser

但是如果用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;
    //窗体中的其它语句
}


这样就完美实现了外窗口无原生按钮(最大最小关闭),无边框,一点边框都没有。

备忘用

当当当当当!

推荐阅读:
  1. JS正则与注释的冲突
  2. 解决WebBrowser边框的问题

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

webbrowser wpf 边框

上一篇:MySQL中count如何统计行数

下一篇:[IOS]包含增删改查移动的tableView展示+plist文件保存+程序意外退出保存Demo

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》