当前位置:首页 > Windows程序 > 正文

WPF与输入法冲突研究之一:百度输入法会导致WPF程序的崩溃!

2021-03-25 Windows程序

>>>>>>>模拟场景<<<<<<<<<

客户:能用WPF给我编写个小程序吗?

程序员:哦,什么样的小程序?

客户:一旦我输入什么东西,你就给我弹出一个警告框。

程序员:这么简单?!还有别的要求吗?

客户支持各种输入法,不能崩溃!

程序员:哦,收您500可以吗?

客户:嗯,不贵~程序员:(嘿嘿,人傻钱多)

>>>>>>>程序员开始努力的写代码<<<<<<<<<

程序员心说,这么简单的程序,就不用XAML了,一个cs文件就搞定,看我的!

using System;  

using System.Windows;  

using System.Windows.Controls;  

  

namespace BaiduCrashesWPF  

{  

    /// <summary>  

    /// Interaction logic for App.xaml  

    /// </summary>  

    public class Program  

    {  

        [STAThread]  

        static void Main(string[] args)  

        {  

            TextBox txtBox = new TextBox();  

            txtBox.Width = 400;  

            txtBox.TextChanged += txtBox_TextChanged;  

  

            Window mainWin = new Window();  

            mainWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;  

            mainWin.Content = txtBox;  

            mainWin.SizeToContent = SizeToContent.WidthAndHeight;  

  

            Application app = new Application();  

            app.ShutdownMode = ShutdownMode.OnMainWindowClose;  

            app.Run(mainWin);  

        }  

  

        static void txtBox_TextChanged(object sender, TextChangedEventArgs e)  

        {  

            MessageBox.Show("用中文输入法了吗?假如你用了,那么这个程序马上就要崩溃了!");  

        }  

    }  

}  



好了,,运行下试试。。。输入中文!打“中国”两个字(一定要2个字哦)!哇,对话框弹出来了!哇,程序崩溃了!!!TNND!经测试,百度输入法,谷歌v2输入法、QQ、搜狗输入法都会导致程序的崩溃。微软拼音输入法不会,谷歌v3不会。

具体原因,见以后的博文~~~

WPF与输入法冲突研究之一:百度输入法会导致WPF程序的崩溃!

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/67347.html