csharp 在Windows 8.1和10上在cef中输入中文字符的解决方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 在Windows 8.1和10上在cef中输入中文字符的解决方法相关的知识,希望对你有一定的参考价值。

// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System.Windows.Controls;
using System.Windows.Input;
using CefSharp.Example;
using CefSharp.Wpf.Example.Handlers;

namespace CefSharp.Wpf.Example.Views
{
    public partial class BrowserTabView : UserControl
    {
        public BrowserTabView()
        {
            InitializeComponent();

            browser.RequestHandler = new RequestHandler();
            if (CefSharpSettings.WcfEnabled)
            {
                browser.RegisterJsObject("bound", new BoundObject());
            }
            browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject());

            browser.LifeSpanHandler = new LifespanHandler();
            browser.MenuHandler = new MenuHandler();
            browser.GeolocationHandler = new GeolocationHandler();
            browser.DownloadHandler = new DownloadHandler();
            
            //NOTE:This code is a workaround for https://github.com/cefsharp/CefSharp/issues/583
            // The `upstream` issue has been flagged as resolved, so hopefully this can be removed
            // in the future.
            //browser.PreviewTextInput += (sender, args) =>
            //{
            //    var host = browser.GetBrowser().GetHost();
            //    var keyEvent = new KeyEvent();

            //    foreach (var character in args.Text)
            //    {
            //        keyEvent.WindowsKeyCode = character;
            //        keyEvent.Type = KeyEventType.Char;
            //        host.SendKeyEvent(keyEvent);
            //    }

            //    args.Handled = true;
            //};

            browser.LoadError += (sender, args) =>
            {
                // Don't display an error for downloaded files.
                if (args.ErrorCode == CefErrorCode.Aborted)
                {
                    return;
                }

                // Don't display an error for external protocols that we allow the OS to
                // handle. See OnProtocolExecution().
                //if (args.ErrorCode == CefErrorCode.UnknownUrlScheme)
                //{
                //	var url = args.Frame.Url;
                //	if (url.StartsWith("spotify:"))
                //	{
                //		return;
                //	}
                //}

                // Display a load error message.
                var errorBody = string.Format("<html><body bgcolor=\"white\"><h2>Failed to load URL {0} with error {1} ({2}).</h2></body></html>",
                                              args.FailedUrl, args.ErrorText, args.ErrorCode);

                args.Frame.LoadStringForUrl(errorBody, args.FailedUrl);
            };

            CefExample.RegisterTestResources(browser);
        }

        private void OnTextBoxGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            var textBox = (TextBox)sender;
            textBox.SelectAll();
        }

        private void OnTextBoxGotMouseCapture(object sender, MouseEventArgs e)
        {
            var textBox = (TextBox)sender;
            textBox.SelectAll();
        }

    }
}

以上是关于csharp 在Windows 8.1和10上在cef中输入中文字符的解决方法的主要内容,如果未能解决你的问题,请参考以下文章

为啥 LWJGL 仅在 Windows 上在以前和当前的游戏状态之间闪烁?

csharp 在Windows 10上实现“Aero Glass”模糊的C#结构

Windows 8.1 和 Windows 10 应用程序问题

构建兼容8.1和10的Windows应用程序

Windows 8.1一直显示应用更改是怎么回事??

如何在 Windows Phone 8.1 / Windows 10 上创建自定义 VirtualizingPanel?