WinForm IME????BUG???????
???????????? ???????[ 2015/11/16 13:29:03 ] ??????????????????
??????WinForm IME????BUG?????????????????.NET Framework 2.0??WinForm?У???????????BUG?????BUG??????????????μ?VS2010???????????????????????o??棬?????????Щ????????BUG????????????????????????????????????WinForm??????????????????????????????????????????????“??????Ч??”????????????????????????????ImeMode.OnHalf???????????????????????????????л?????????????????????(ImeMode.OnHalf?????ImeMode.On????)??????????????????????????????????????????????(????????)??????????????????????????£?
????protected override void OnLoad(EventArgs e)
????{
????KeyPreview = true;
????DrawTextboxes();
????// ???????????????
????ImeMode = ImeMode.OnHalf;
????base.OnLoad(e);
????}
???????????
???????????????imm32.dll API????????????????????????????WinForm??????????????????????????????д??????????OnActivited??????ɡ????????????Control??ImeMode??????????????????????????????μ????????????????????????OK???????????????~~??
/* WinForm IME????BUG???????
* ????csc.exe /target:winexe WinformImeBugFixed.cs
*/
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
namespace WinformImeBugFixed
{
public class Form1 : Form
{
#region ???????BUG
//???????BUG
[DllImport("imm32.dll")]
public static extern IntPtr ImmGetContext(IntPtr hwnd);
[DllImport("imm32.dll")]
public static extern bool ImmSetOpenStatus(IntPtr himc?? bool b);
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
IntPtr HIme = ImmGetContext(this.Handle);
ImmSetOpenStatus(HIme?? true);
}
#endregion
#region ?????????
private void DrawTextboxes()
{
Controls.Clear();
int x?? y?? d;
x = y = d = 10;
for (int i = 0; i < 2; i++)
{
var textbox = new TextBox()
{
Width = 200??
Location = new Point(x?? y)
};
y += textbox.Height + d;
textbox.DataBindings.Add("Text"?? textbox?? "ImeMode");
Controls.Add(textbox);
}
}
private void DrawButton()
{
var button = new Button()
{
Text = "Show Form2"??
Location = new Point(10?? 70)
};
button.Click += delegate
{
var form2 = new Form();
form2.Text = "Form2";
var textbox = new TextBox()
{
Width = 200??
Location = new Point(10?? 10)
};
form2.Controls.Add(textbox);
form2.Show();
};
Controls.Add(button);
}
protected override void OnLoad(EventArgs e)
{
Text = "IME????BUG??? F5-??? F1-????";
KeyPreview = true;
DrawTextboxes();
DrawButton();
base.OnLoad(e);
}
public Form1()
{
InitializeComponent();
}
protected override void OnKeyDown(KeyEventArgs e)
{
try { HandleKeyDown(e); }
finally { base.OnKeyDown(e); }
}
private void HandleKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.F5) DrawTextboxes();
else if (e.KeyCode == Keys.F1) NavigateBlog();
}
private void NavigateBlog()
{
System.Diagnostics.Process.Start("http://hi.baidu.com/wingingbob/blog/item/20741734532af846251f14f1.html");
}
#endregion
#region Form1?????
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.SuspendLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(6F?? 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(240?? 100);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
#region ????
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
#endregion
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11