WPF去边框与webbrowser的冲突
最近弄了弄WPF,最简单的,一个窗体,里面加个webbrowser
但是如果用AllowTransparency="True" WindowStyle="None"的话,的确窗体的边框和原生按钮去掉了
但是,webbrowser里打开的页面也看不见了
看了一圈网上的解决办法,基本上都是那个WebBrowserOverlay,真是个大坑,一点不好用
所以找到另一个办法,就是用SetWindowLong来解决,当然AllowTransparency跟WindowSytle都要去掉
首先建一个类,比如NativeMethods.cs
classNativeMethods{publicconstintWS_CAPTION=0x00C0000;publicconstintWS_BORDER=0x00800000;publicconstintWS_DLGFRAME=0x00400000;publicconstintGWL_STYLE=-16;[DllImport("user32",EntryPoint="GetWindowLong")]publicstaticexternintGetWindowLong(IntPtrhandle,intsytle);[DllImport("user32",EntryPoint="SetWindowLong")]publicstaticexternintSetWindowLong(IntPtrhandle,intoldStyle,intnewStyle);}
然后在你的窗体代码中,比如MainWindow.xaml.cs
publicpartialclassMainWindow:Window{IntPtrhwnd=newSystem.Windows.Interop.WindowInteropHelper(this).Handle;intoldStyle=NativeMethods.GetWindowLong(hwnd,NativeMethods.GWL_STYLE);NativeMethods.SetWindowLong(hwnd,NativeMethods.GWL_STYLE,oldStyle&~NativeMethods.WS_BORDER&~NativeMethods.WS_CAPTION&~NativeMethods.WS_DLGFRAME);}publicMainWindow(){InitializeComponent();this.Loaded+=Window_Loaded;//窗体中的其它语句}
这样就完美实现了外窗口无原生按钮(最大最小关闭),无边框,一点边框都没有。
备忘用
当当当当当!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。