如何在运行时添加多个文本框 [英] how to add multiple textbox at runtime

查看:137
本文介绍了如何在运行时添加多个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在运行时,当任何文本框同时离开时,还有一个文本框在它下面,当该文本框离开时,另一个文本框就会出现在它下面,这个过程一直持续到我想要,整个应该在运行时。

i want that at runtime when any textbox get leave at same time one more textbox comes under it and when that textbox get leave another textbox comes under it and this process get continued till i want and whole should be at runtime.

推荐答案

Google [ ^ ]你是朋友吗但是,创建一个可能无限的TextBoxes序列的目的是什么?
Google[^] is you friend. However, what's the purpose of creating a possibly infinite sequence of TextBoxes?


你究竟是怎么做的(而且我认为这是一个非常非常糟糕的想法 - 你如何摆脱这个循环?)将取决于您正在使用的环境:例如,一个网站将与WinForms应用程序完全不同。

但原则是:

处理LostFocus文本框的事件。

在事件处理程序中,创建一个新的文本框并将其添加到页面/表单。



对于WinForms:

Exactly how you do that (and I think it is a very, very poor idea - how do you get out of this loop?) will depend on the environment you are working in: a website will be completely different from a WinForms app for example.
But the principle is:
Handle the LostFocus event for the textbox.
In the event handler, create a new Textbox and add it to the page / form.

For WinForms:
void existingTextBox_LostFocus(object sender, EventArgs e)
    {
    TextBox existing = sender as TextBox;
    if (existing != null)
        {
        TextBox newTextBox = new TextBox();
        newTextBox.LostFocus += new EventHandler(existingTextBox_LostFocus);
        newTextBox.Location = new Point(existing.Location.X, existing.Location.Y + 30);
        newTextBox.Size = existing.Size;
        Controls.Add(newTextBox);
        }
    }


这篇关于如何在运行时添加多个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆