0

我想要发生的是,当单击一个文本框时,会显示一个弹出式键盘,并且我在键盘上输入的任何内容都将被放入文本框中,但是没有任何反应,但是当我使用记事本时,它可以工作。我怎样才能解决这个问题?

这是我的主要表单代码:

    private void textBox1_MouseClick(object sender, MouseEventArgs e)
    {
        Form1 frm1 = new Form1();
        frm1.ShowDialog();
    }

这是我的弹出键盘代码

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)
    {

    }
}
4

3 回答 3

0

如果您手动添加了测试框,请确保您像这样连接到 MouseEventHandler:

this.textBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.textBox1_MouseClick);

当您的表单加载时。

于 2013-03-03T03:59:53.800 回答
0

我通过添加这行代码解决了这个问题

[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
    public static extern IntPtr GetDesktopWindow();

                param.Style = 0x40000000 | 0x4000000;
            param.Parent = GetDesktopWindow();
于 2013-03-03T06:07:02.980 回答
0

使用form1.Show()...不ShowDialog()

于 2013-03-03T03:45:39.363 回答