RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
WPF去边框与webbrowser的冲突-创新互联

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

成都创新互联专业IDC数据服务器托管提供商,专业提供成都服务器托管,服务器租用,达州服务器托管达州服务器托管,成都多线服务器托管等服务器托管服务。

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

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

备忘用

当当当当当!

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


分享名称:WPF去边框与webbrowser的冲突-创新互联
地址分享:http://cqwzjz.cn/article/dpegdp.html