WPF与输入法冲突研究之三:韩文输入法在不同平台,WinForm/WPF下的区别
2013-01-05 12:23
453 查看
输入法的问题,已经把我折腾的精疲力尽了。。终于在Win7平台上,中日韩三国输入法能够在WPF上正确使用之后,WinXP又不行了。。。韩文输入法无法正确使用。。。
好吧,只能做几个小程序,测试下韩文输入法在不同平台,不同框架(WinForm/WPF)下的区别:
1. 韩文在输入过程中,很奇特,会有一个高亮闪烁的小方块,这个表示,当前的韩文字符正在构造中,他会随着你之后的输入而变化,这个高亮的小方块,有什么奇特的呢?在WPF的TextBox里面,TextBox的SelectionLength属性,返回的是1(表示有一个字符被选中),而在WinForm下面,返回的是0(表示没有字符被选中)。这个在Win7/WinXP平台下,都是一致的。看截图:
Win7 WPF/WinForm (输入t,组出来的韩文应该是ㅅ,注意Selection Length和Selection Start):
WinXP WPF/WinForm: (XP下WinForm的小方块有点小。。。)
好,每个UI都有一个CheckBox,这个的意思就是程序每个10毫秒会自动调用txtBox.Select(txtBox.SelectionStart, 0);语句,这个有什么意义呢?这句语句相当于把Selection清除。我就想看看,在清除了Selection之后,韩文输入法能否正常工作。经测试,2个平台下WinForm都能正常工作,而WPF只有在Win7平台才能正常工作,在XP下,韩文输入法有2个大问题:一个是不能正常组字,二就是光标会跑到输入的字符前面。。。看截图:
Win7 WPF/WinForm ([b]输入ty,组出来的韩文应该是쇼[/b],注意Auto
Call已经开启,这时候Selection Length都变成了0),Win7下,仍然有个小方块,而且组出来的字是正确的。Winform把t和ty组出来的字都加到了TextBox里!
WinXP WPF/WinForm (注意Auto Call已经开启,这时候Selection Length都变成了0),WPF没有组字,直接把t和y变成了2个字符,而且第二个字符插在了第一个字符之前。WinForm和Win7平台一样:
总结:
附上代码:
Wpf:
WinForm:
好吧,只能做几个小程序,测试下韩文输入法在不同平台,不同框架(WinForm/WPF)下的区别:
1. 韩文在输入过程中,很奇特,会有一个高亮闪烁的小方块,这个表示,当前的韩文字符正在构造中,他会随着你之后的输入而变化,这个高亮的小方块,有什么奇特的呢?在WPF的TextBox里面,TextBox的SelectionLength属性,返回的是1(表示有一个字符被选中),而在WinForm下面,返回的是0(表示没有字符被选中)。这个在Win7/WinXP平台下,都是一致的。看截图:
Win7 WPF/WinForm (输入t,组出来的韩文应该是ㅅ,注意Selection Length和Selection Start):
WinXP WPF/WinForm: (XP下WinForm的小方块有点小。。。)
好,每个UI都有一个CheckBox,这个的意思就是程序每个10毫秒会自动调用txtBox.Select(txtBox.SelectionStart, 0);语句,这个有什么意义呢?这句语句相当于把Selection清除。我就想看看,在清除了Selection之后,韩文输入法能否正常工作。经测试,2个平台下WinForm都能正常工作,而WPF只有在Win7平台才能正常工作,在XP下,韩文输入法有2个大问题:一个是不能正常组字,二就是光标会跑到输入的字符前面。。。看截图:
Win7 WPF/WinForm ([b]输入ty,组出来的韩文应该是쇼[/b],注意Auto
Call已经开启,这时候Selection Length都变成了0),Win7下,仍然有个小方块,而且组出来的字是正确的。Winform把t和ty组出来的字都加到了TextBox里!
WinXP WPF/WinForm (注意Auto Call已经开启,这时候Selection Length都变成了0),WPF没有组字,直接把t和y变成了2个字符,而且第二个字符插在了第一个字符之前。WinForm和Win7平台一样:
总结:
附上代码:
Wpf:
using System; using System.Windows; using System.Windows.Interop; using System.Windows.Threading; namespace Wpf.ImeSelectionTracker { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); new DispatcherTimer(TimeSpan.FromSeconds(0.01), DispatcherPriority.Normal, (sender, e) => { UpdateImeState(); }, this.Dispatcher); } private void UpdateImeState() { lblSelectionStart.Content = "N/A"; lblSelectionLength.Content = "N/A"; lblSelectionString.Content = "N/A"; try { IntPtr hwndTextBox = (HwndSource.FromVisual(this.txtBox) as HwndSource).Handle; lblSelectionStart.Content = txtBox.SelectionStart; lblSelectionLength.Content = txtBox.SelectionLength; lblSelectionString.Content = txtBox.Text.Substring(txtBox.SelectionStart, txtBox.SelectionLength); if(chkAutoSelection.IsChecked == true) txtBox.Select(txtBox.SelectionStart, 0); } catch { } } } }
WinForm:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WinForm.ImeSelectionTracker { public partial class Form1 : Form { public Form1() { InitializeComponent(); Timer timer = new Timer(); timer.Interval = 10; timer.Tick += (sender, e) => { UpdateImeState(); }; timer.Start(); } private void UpdateImeState() { lblSelectionStart.Text = "N/A"; lblSelectionLength.Text = "N/A"; lblSelectionString.Text = "N/A"; try { IntPtr hwndTextBox = this.txtBox.Handle; lblSelectionStart.Text = txtBox.SelectionStart.ToString(); lblSelectionLength.Text = txtBox.SelectionLength.ToString(); lblSelectionString.Text = txtBox.Text.Substring(txtBox.SelectionStart, txtBox.SelectionLength); if (chkBox.Checked) txtBox.Select(txtBox.SelectionStart, 0); } catch { } } } }
相关文章推荐
- WPF与输入法冲突研究之三:韩文输入法在不同平台,WinForm/WPF下的区别
- WPF与输入法冲突研究之二:TextInput事件的BUG?
- WPF与输入法冲突研究之一:百度输入法会导致WPF程序的崩溃!
- WPF与输入法冲突研究之二:TextInput事件的BUG?
- WPF与输入法冲突研究之一:百度输入法会导致WPF程序的崩溃!
- .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)
- 不同平台编译器区别及迁移注意事项
- WPF 和WinForm的MeeageBox不同
- Winform、WPF和silverlight的区别
- WinForm,WPF,SilverLight三者区别和特性
- 黑马程序员—关于WinForm和WPF的一些不同点
- __stdcall __cdecl 在不同平台上的区别
- 不同平台(mac、windows—wpf、web、ios、android)下实现页面的转场动画
- wpf 中文输入法回车事件和控件的回车事件冲突问题
- WPF和Winform的区别
- restlet 不同平台框架的区别
- C#控制台程序,Winform,WPF的区别
- 【Java】奇怪的考试题:128与127对于==(等于号)的不同区别研究!
- Winform、WPF、Silverlight、MFC区别与联系