简体   繁体   中英

C# Textbox is not showing

private TextBox txtBoxDragPoint = new TextBox();

private void rtbLogicCode_MouseDown(object sender, MouseEventArgs e)
{
    if (dragInfo.Item2 == true)
    {
        //MessageBox.Show("Works");
        Point p = new Point(e.X, e.Y);

        txtBoxDragPoint.Name = dragInfo.Item1;
        txtBoxDragPoint.Text = dragInfo.Item1;
        txtBoxDragPoint.Location = p;
        txtBoxDragPoint.Size = new Size(100, 21);
        txtBoxDragPoint.Show();
    }
} 

I have a textbox that is supposed to show when the user clicks on the RichTextBox. The event and the boolean condition is fine as it is displaying the messagebox however, it is not showing the textbox itself. Is there something else I have to do?

Edit: As mentioned in the replies, I have made the following addendum but the textbox still is not showing:

        txtBoxDragPoint.Name = dragInfo.Item1;
        txtBoxDragPoint.Text = dragInfo.Item1;
        txtBoxDragPoint.Location = p;
        txtBoxDragPoint.Size = new Size(100, 21);
        this.Controls.Add(txtBoxDragPoint);
        txtBoxDragPoint.Show();

I don't know if this information is any relevant but the RTB is added as a control of the tabcontrol, which tabcontrol is added as a control of the form.

代替txtBoxDragPoint.Show()您必须将该文本框添加到form

this.Controls.Add(txtBoxDragPoint);

You have to add the text box to the form

this.Controls.Add(txtBoxDragPoint );
txtBoxDragPoint .BringToFront();

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.

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