I want to creat a button that when I click on it it will generate a TextBox ,please tell me how

Recommended Answers

All 6 Replies

You need to associate a method with the button's "on click" event.

The code in the method will need to generate the textbox.

(Did you mean a message box?)

If you want more detailed help you're going to need to tell us more about your code environment, and preferably show us some code to show that you're trying to solve the problem.

no new textbox in a another position

You need to associate a method with the button's "on click" event.

The code in the method will need to generate the textbox.

If you want more detailed help you're going to need to tell us more about your code environment, and preferably show us some code to show that you're trying to solve the problem.

As Murton says, you need to provide more information.

Well you just drag a button and a textbox on a form.
than go through the property window and make the visible property of texbox is false.

and than on click event of button just write this code:

textbox1.Visible=true;

Hope this works.......:)

Here is one example of creating a control in code:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace daniweb
{
  public partial class frmCreateTB : Form
  {
    public frmCreateTB()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      TextBox tb = new TextBox();
      tb.Location = new Point(0, 0); //This is the top-left corner of the form
      tb.Text = "Auto created textbox!!!!!";
      using (Graphics g = this.CreateGraphics())
      {
        tb.Width = Convert.ToInt32(Math.Ceiling(g.MeasureString(tb.Text, tb.Font).Width));
      }
      this.Controls.Add(tb);
    }
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.