What I want to happen is that when a textbox is clicked a pop up keyboard will show and whatever i type on the keyboard will be putt in the textbox, but nothing happen but when I use notepad, it works. How can I fix this?
Here is my main form code:
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
Form1 frm1 = new Form1();
frm1.ShowDialog();
}
And here is my code for pop up keyboard
public partial class Form1 : Form
{
const int WS_EX_NOACTIVATE = 0x08000000;
//this line of code fixed the issue
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();
public Form1()
{
InitializeComponent();
}
protected override CreateParams CreateParams
{
get
{
CreateParams param = base.CreateParams;
param.ExStyle |= WS_EX_NOACTIVATE;
//This line of code fix the issues
param.Style = 0x40000000 | 0x4000000;
param.Parent = GetDesktopWindow();
return param;
}
}
private void button1_Click(object sender, EventArgs e)
{
SendKeys.Send("1");
}
private void button3_Click(object sender, EventArgs e)
{
SendKeys.Send("2");
}
private void button4_Click(object sender, EventArgs e)
{
SendKeys.Send("3");
}
private void button2_Click(object sender, EventArgs e)
{
}
}
使用form1.Show()
...而不是ShowDialog()
If you manually added the testbox make sure you hook into the MouseEventHandler like so:
this.textBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.textBox1_MouseClick);
when your form loads.
I fixed the issue by just adding this line of code
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();
And
param.Style = 0x40000000 | 0x4000000;
param.Parent = GetDesktopWindow();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.