如何勾选CefSharp鼠标点击

时间:2016-11-06 15:12:50

标签: c# cefsharp

我希望有时会挂钩并取消所有鼠标按下事件(按某些条件)。 当我尝试监听事件MouseClick,Click /或ovvrride方法OnMouseClick和OnClick - 它不起作用。 现在,我使用道具已启用来阻止浏览器,但是它的块浏览器无法查看/滚动网页。

public class CustBrw : ChromiumWebBrowser {
    public CustBrw() : base("") {
        doStart();
    }

    public CustBrw(string address) : base(address) {
        doStart();
    }

    private void doStart() {
        this.Dock = System.Windows.Forms.DockStyle.Fill;
        this.FrameLoadEnd += CustBrw_FrameLoadEnd;
        this.MouseClick += CustBrw_MouseClick;
    }

    private void CustBrw_MouseClick(object sender, MouseEventArgs e) {
        // dont work
        MessageBox.Show("brw clicked!");
    }

    #region Disable Browser
    private bool IsEnabled = true;

    public void EnabledBrowser() {
        ChangeBrowserDisabled(true);
    }

    public void DisableBrowser() {
        ChangeBrowserDisabled(false);
    }

    protected void ChangeBrowserDisabled(bool State) {
        if (InvokeRequired)
            Invoke((Action) delegate {
                if (this.IsEnabled != State) {
                    this.IsEnabled = State;
                    this.EvaluateScriptAsync("$('body').css({background : " + (State ? "'#fff'" : "'#e0e0e0'") + "});");
                }
            });
        else {
            if (this.IsEnabled != State) {
                this.IsEnabled = State;
                this.EvaluateScriptAsync("$('body').css({background : " + (State ? "'#fff'" : "'#e0e0e0'") + "});");
            }
        }
    }
    #endregion

    private bool IsWatingUri(string Uri) {
        if (Uri.ToLower().StartsWith("some uri"));
            return true;
        else
            return false;
    }

    [JavascriptIgnore]
    public Task<EventArgs> LoadPageAsync(string address = null) {
        var tcs = new TaskCompletionSource<EventArgs>();

        EventHandler<LoadingStateChangedEventArgs> handler = null;
        handler += (sender, args) =>
        {
            this.DisableBrowser();
            if (!args.IsLoading) {
                this.LoadingStateChanged -= handler;
                this.EnabledBrowser();
                tcs.TrySetResult(args);
            }
        };

        this.LoadingStateChanged += handler;

        if (!string.IsNullOrEmpty(address)) {
            this.Load(address);
        }
        return tcs.Task;
    }

    private void CustBrw_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) {
        if (!e.Frame.IsMain)
            return;

        if (!IsWatingUri(e.Url))
            return;

        GetTestTypeAsync().ContinueWith((scriptResult) =>
        {
            try {
                // DISABLE
                this.DisableBrowser();

                // DO SOME SPEC WORKS (with callback from js)
                this.CreateCallbackFunction().Wait();  // register JS-object
                if (IsAutoMode)
                    this.SubscribeCallbackFunction().Wait();

                if (IsAutoMode)
                    this.ExecuteCallbackFunction();

            } finally {
                // ENABLE
                this.EnabledBrowser();
            }
        });
    }
 .....
}

在启用标志的情况下 - 阻止了整个浏览器控件,但希望能够仅使用浏览器进行查看(通过输入您的标志)。 有人面临类似的挑战吗?

0 个答案:

没有答案