简体   繁体   English

Windows窗体文本框是不可编辑的

[英]Windows Forms Textbox is uneditable by accident

I have an application which asks the user a few simple questions. 我有一个应用程序,它向用户询问一些简单的问题。 The user is supposed to input the answer by typing it into a TextBox. 用户应该通过在文本框中键入答案来输入答案。 When I render the Windows Form though, the TextBox is greyed out, blends in with the background, and is uneditable. 但是,当我渲染Windows窗体时,TextBox变灰,与背景混合并且不可编辑。

Here's my code: 这是我的代码:

public string waitForText(Point Locution)
    {
        TextBox WriteAnswerHere = new TextBox();
        WriteAnswerHere.Location = Locution;
        WriteAnswerHere.ReadOnly = false;
        WriteAnswerHere.Focus();
        this.Controls.Add(WriteAnswerHere);

        int waiting = 1;
        while (waiting == 1)
        {
            if (Control.ModifierKeys == Keys.Enter)
            {
                waiting = 0;
            }

        }

        string HowYouAre = WriteAnswerHere.Text;
        this.Controls.Remove(WriteAnswerHere);
        return HowYouAre;
    }

The input is supposed to be given to the application when the Enter key is pressed, hence the (Control.ModifierKeys == Keys.Enter); 当按下Enter键时,应该将输入提供给应用程序,因此(Control.ModifierKeys == Keys.Enter); Any suggestions on what I am doing wrong? 关于我在做什么错的任何建议吗?

You shouldn't use a while loop to detect specific key events. 您不应该使用while循环来检测特定的按键事件。 Your while loop is holding up the form. 您的while循环正在阻止表单。 I suggest you check out these articles on Events and Event handlers for Windows forms. 我建议您查看有关Windows窗体的事件和事件处理程序的这些文章。

http://msdn.microsoft.com/en-us/library/dacysss4.aspx http://msdn.microsoft.com/en-us/library/dacysss4.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM