Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C“WPF在窗口上以AllowTransparency=”显示WebBrowser;“真的”;不显示_C#_Wpf_Webbrowser Control - Fatal编程技术网

C# C“WPF在窗口上以AllowTransparency=”显示WebBrowser;“真的”;不显示

C# C“WPF在窗口上以AllowTransparency=”显示WebBrowser;“真的”;不显示,c#,wpf,webbrowser-control,C#,Wpf,Webbrowser Control,我正在显示一个带有WebBrowser控件的窗口。 我希望窗口是无框的,因此我设置了WindowStyle=“无” 这可以工作,但会在窗口周围显示彩色边框。 AllowTransparency=“true”将删除此选项,但不再显示WebBrowser(按钮为) 我已找到,但无法使其工作(SetWindowsLong参数错误) windowx:Class=“ZoomBrowserWPF.WebWindow” xmlns=”http://schemas.microsoft.com/winfx/200

我正在显示一个带有WebBrowser控件的窗口。 我希望窗口是无框的,因此我设置了WindowStyle=“无” 这可以工作,但会在窗口周围显示彩色边框。 AllowTransparency=“true”将删除此选项,但不再显示WebBrowser(按钮为)

我已找到,但无法使其工作(SetWindowsLong参数错误)

windowx:Class=“ZoomBrowserWPF.WebWindow”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local=“clr命名空间:UMenu”
Title=“Test”Height=“605”Width=“700”ResizeMode=“CanResizeWithGrip”
Loaded=“Window\u Loaded”Unload=“Window\u Unload”
WindowStyle=“无”
背景=“透明”
Left=“1”Top=“1”
UseLayoutRounding=“True”SizeChanged=“Window\u SizeChanged”>

它不适用于WPF欺骗,因为WebBrowser控件实际上不是WPF控件。 它是一个包装的ActiveX IE web浏览器控件,不是由WPF呈现的

也许你的问题与这篇文章有关

老实说,如果可能的话,试着放弃这种糟糕的网络控制,改用其他方法。
有一些具有适当WPF支持的免费替代品,如Awesomium.NET、CefSharp或CefGlue.NET(均基于铬)。

我查看了您发布的源代码,它对我有用。 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace PAUL.Allgemein.Seiten
{
/// <summary>
/// Interaktionslogik für Robbe.xaml
/// </summary>
public partial class Robbe : Window
{
    #region The Classic Window API
    //The SendMessage function sends a message to a window or windows.
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

    //ReleaseCapture releases a mouse capture
    [DllImportAttribute("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    public static extern bool ReleaseCapture();

    //SetWindowLong lets you set a window style
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern int SetWindowLong(IntPtr hWnd, int nIndex, long dwNewLong);
    #endregion

    const int GWL_STYLE = -16;
    const long WS_POPUP = 2147483648;

    //private const int GWL_STYLE = -16;
    //private const int WS_SYSMENU = 0x80000;
    //[DllImport("user32.dll", SetLastError = true)]
    //private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    //[DllImport("user32.dll")]
    //private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    public Robbe()
    {

        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
        SetWindowLong(hWnd, GWL_STYLE, WS_POPUP);
    }
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Runtime.InteropServices;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Interop;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Shapes;
名称空间PAUL.allgemain.Seiten
{
/// 
///für Robbe.xaml跨部门物流
/// 
公共部分类Robbe:窗口
{
#使用经典的windowapi
//SendMessage函数向一个或多个窗口发送消息。
[DllImport(“user32.dll”,CharSet=CharSet.Auto,SetLastError=false)]
静态外部IntPtr SendMessage(IntPtr hWnd、uint Msg、int wParam、int lParam);
//释放捕获释放鼠标捕获
[DllImportAttribute(“user32.dll”,CharSet=CharSet.Auto,SetLastError=false)]
公共静态外部bool ReleaseCapture();
//SetWindowLong用于设置窗口样式
[System.Runtime.InteropServices.DllImport(“user32.dll”)]
静态外部int SetWindowLong(IntPtr hWnd、int nIndex、long dwNewLong);
#端区
const int GWL_STYLE=-16;
const long WS_POPUP=2147483648;
//私有常量int GWL_STYLE=-16;
//私有常量int WS_SYSMENU=0x80000;
//[DllImport(“user32.dll”,SetLastError=true)]
//私有静态外部intgetWindowLong(intptrhwnd,intnindex);
//[DllImport(“user32.dll”)]
//私有静态外部intsetWindowLong(IntPtr hWnd、intnindex、intdwnewlong);
公共罗比()
{
初始化组件();
}
已加载私有无效窗口(对象发送器、路由目标)
{
IntPtr hWnd=new System.Windows.Interop.WindowInteropHelper(this.Handle);
SetWindowLong(hWnd、GWL_样式、WS_弹出窗口);
}
}
}
以及Xaml代码:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Robbe" Height="300" Width="300"
    Loaded="Window_Loaded">
<Grid>
    <!-- Creates the shadow on the right and bottom -->
    <Border Focusable="False" BorderBrush="Gray"           
        BorderThickness="0,0,2,2"
        CornerRadius="10"
        Background="Beige" >
        <WebBrowser Source="C:\Users\nicholas\Desktop\puale\PAUL\bin\Debug\robbe.swf" Margin="62,71,69,56"></WebBrowser>
    </Border>
</Grid>
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml"
Title=“Robbe”Height=“300”Width=“300”
已加载=“窗口已加载”>

这是一个老问题,但我想发布我为使其正常工作所做的工作

当您想要创建一个没有边框的窗口,该窗口可以调整大小,并且能够承载指向URL的WebBrowser控件或框架控件,而您根本无法创建URL时,所述控件的内容将显示为空,如OP所述

我找到了一个解决办法;在窗口中,如果您将WindowsStyle设置为None,将ResizeMode调整为NoResize(恕我直言,完成后您仍然可以调整大小),然后确保取消选中AllowTransparency,您将有一个静态大小的窗口,没有边框,并将显示浏览器控件

现在,您可能仍然希望能够调整大小,对吗?我们可以通过互操作调用:

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    [DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();

    //Attach this to the MouseDown event of your drag control to move the window in place of the title bar
    private void WindowDrag(object sender, MouseButtonEventArgs e) // MouseDown
    {
        ReleaseCapture();
        SendMessage(new WindowInteropHelper(this).Handle,
            0xA1, (IntPtr)0x2, (IntPtr)0);
    }

    //Attach this to the PreviewMousLeftButtonDown event of the grip control in the lower right corner of the form to resize the window
    private void WindowResize(object sender, MouseButtonEventArgs e) //PreviewMousLeftButtonDown
    {
        HwndSource hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        SendMessage(hwndSource.Handle, 0x112, (IntPtr)61448, IntPtr.Zero);
    }

瞧,这是一个WPF窗口,没有边框,仍然可以移动和调整大小,而且不会失去与WebBrowser等控件的兼容性。我知道这是一个老问题,但我今天遇到了完全相同的问题,我用

ResizeMode="NoResize"
而不是

Allowstransparency="true"

ResizeMode也会删除注释边框,并且不会影响WebBrowser控件。在这种情况下,似乎是解决问题的最简单方法:)

您可以做的是将webbrowser控件包装成一个弹出控件,该控件具有可设置为false的AllowTransparency属性,当然,它浮动的缺点是使webbrowser控件适合您的targetplacement

 <Grid Grid.Row="1"
       Grid.Column="2">
       <Grid Name="grdBrowser" 
             Background="White"></Grid>
                <Popup AllowsTransparency="False" 
                       Height="{Binding Path=Height,ElementName=grdBrowser}"
                       Width="{Binding Path=Width,ElementName=grdBrowser}"
                       IsOpen="True"
                       Placement="Mouse" 
                       PlacementTarget="{Binding ElementName=grdBrowser}">
                            <WebBrowser/>
                </Popup>

 </Grid>


这与
allowTransparency=“true”
属性设置无关。。。卸下它,然后查看。也许你应该适当地编辑你的问题标题?这就是我所使用的:-)user3231903的回复是一个很好的选择(因此评级)如果你有并且想要使用透明度,我推荐这篇文章
 <Grid Grid.Row="1"
       Grid.Column="2">
       <Grid Name="grdBrowser" 
             Background="White"></Grid>
                <Popup AllowsTransparency="False" 
                       Height="{Binding Path=Height,ElementName=grdBrowser}"
                       Width="{Binding Path=Width,ElementName=grdBrowser}"
                       IsOpen="True"
                       Placement="Mouse" 
                       PlacementTarget="{Binding ElementName=grdBrowser}">
                            <WebBrowser/>
                </Popup>

 </Grid>