【问题标题】:Awesomium Popup - ShowCreatedWebView ExampleAwesomium 弹出窗口 - ShowCreatedWebView 示例
【发布时间】:2014-09-17 12:37:05
【问题描述】:

我在 Visual Studio 2012 中使用带有 C# Windows Forms 的 Awesomium 1.7.4.2。我无法通过单击超链接打开弹出窗口。

我在表单中有一个WebControlShowCreatedWebView 正在捕获该事件,但在里面我不知道如何打开一个新窗口弹出子窗口,将数据传递给 POST。

我知道我必须使用 ShowCreatedWebView 并尝试使用 SDK 示例但未成功:

http://docs.awesomium.net/?tc=E_Awesomium_Core_IWebView_ShowCreatedWebView

它只是不起作用!

谁能在C# windows forms 中举个例子?

谁能帮帮我?

【问题讨论】:

    标签: c# winforms c#-4.0 popupwindow awesomium


    【解决方案1】:

    记得在超链接中添加target="_blank"

    <a id="foo" href="http://...." target="_blank">Test link</a>
    

    然后您只需要捕获ShowCreatedWebView 事件,如下所示:

    webControl1.ShowCreatedWebView += OnShowNewView;
    
    internal static void OnShowNewView( object sender, ShowCreatedWebViewEventArgs e )
    {
        // Your link is in e.TargetURL
        // You can handle it like in docs you've mentioned 
    }
    

    你可以用外部浏览器打开它,像这样:

    System.Diagnostics.Process.Start(e.TargetURL.ToString());
    

    您可以像在 Awesomium 文档中一样处理它:

        internal static void OnShowNewView(object sender, ShowCreatedWebViewEventArgs e)
        {
            WebControl webControl = sender as WebControl;
    
            if (webControl == null)
                return;
    
            if (!webControl.IsLive)
                return;
    
            ChildWindow newWindow = new ChildWindow();
    
            if (e.IsPopup && !e.IsUserSpecsOnly)
            {
                Int32Rect screenRect = e.Specs.InitialPosition.GetInt32Rect();
    
                newWindow.NativeView = e.NewViewInstance;
                newWindow.ShowInTaskbar = false;
                newWindow.WindowStyle = System.Windows.WindowStyle.ToolWindow;
                newWindow.ResizeMode = e.Specs.Resizable ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize;
    
                if ((screenRect.Width > 0) && (screenRect.Height > 0))
                {
                    newWindow.Width = screenRect.Width;
                    newWindow.Height = screenRect.Height;
                }
                newWindow.Show();
                if ((screenRect.Y > 0) && (screenRect.X > 0))
                {
                    newWindow.Top = screenRect.Y;
                    newWindow.Left = screenRect.X;
                }
            }
            else if (e.IsWindowOpen || e.IsPost)
            {
                newWindow.NativeView = e.NewViewInstance;
                newWindow.Show();
            }
            else
            {
                e.Cancel = true;
                newWindow.Source = e.TargetURL;
                newWindow.Show();
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多