Windows Develop Bookmark and Share   
 index > Windows Forms Designer > how to create a textbox by clicking a button
 

how to create a textbox by clicking a button

i got a VS 2008 im new in this world

i will like to know if i can make a text box appear by clicking a button in run time!! thanks by anticipate

ern_jim  Monday, October 20, 2008 1:48 PM

Hi

Here is code.

Code Snippet

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Try

Dim txt As New TextBox

txt.Text = "Test"

txt.Top = Button3.Top + 100

txt.Left = Button3.Left + 100

Me.Controls.Add(txt)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

Change location as per your requirement.

If any error, let me know.

Thank You.

Best Regards

Utkarsh Gajjar

Utkarsh  Monday, October 20, 2008 5:57 PM

Code Snippet

Dim counter As Integer = 8

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim txt As New TextBox

txt.Text = "Test"

txt.Location = New Point(8, counter)

txt.Size = New Size(75, 35)

Me.Controls.Add(txt)

counter += 20

End Sub

You just need to add a counter.

A.D.T.

BeforeAndAfter1974  Monday, October 20, 2008 8:26 PM

Hi ern_jim

I recommend you to use FlowLayoutPanel control. It is very easy to create a new control and add it to its container. You don’t need to calculate the position of each control you want to create. Here is an example.

Code Snippet

void button1_Click(object sender, EventArgs e)

{

Button btn = new Button();

btn.Text = "New Button";

flowLayoutPanel1.Controls.Add(btn);

}

Drag a FlowLayoutPanel control from the ToolBox of Visual Studio onto your form and put a Button(button1) on your form. Each time you click the button1, you will have a new button on the FlowLayoutPanel control.

Wish this can help you.

Sincerely,

Kira Qian

Kira Qian  Wednesday, October 22, 2008 3:02 AM

Hi

Here is code.

Code Snippet

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Try

Dim txt As New TextBox

txt.Text = "Test"

txt.Top = Button3.Top + 100

txt.Left = Button3.Left + 100

Me.Controls.Add(txt)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

Change location as per your requirement.

If any error, let me know.

Thank You.

Best Regards

Utkarsh Gajjar

Utkarsh  Monday, October 20, 2008 5:57 PM

Utkarsh Gajjar thx this is really helpful

but i still got a problem i will like to make that every time i push the button..

i mean to make a lot of text box just by clicking a button for every time i need a new textbox

thanks!!!
ern_jim  Monday, October 20, 2008 7:43 PM

Code Snippet

Dim counter As Integer = 8

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim txt As New TextBox

txt.Text = "Test"

txt.Location = New Point(8, counter)

txt.Size = New Size(75, 35)

Me.Controls.Add(txt)

counter += 20

End Sub

You just need to add a counter.

A.D.T.

BeforeAndAfter1974  Monday, October 20, 2008 8:26 PM

Hi ern_jim

I recommend you to use FlowLayoutPanel control. It is very easy to create a new control and add it to its container. You don’t need to calculate the position of each control you want to create. Here is an example.

Code Snippet

void button1_Click(object sender, EventArgs e)

{

Button btn = new Button();

btn.Text = "New Button";

flowLayoutPanel1.Controls.Add(btn);

}

Drag a FlowLayoutPanel control from the ToolBox of Visual Studio onto your form and put a Button(button1) on your form. Each time you click the button1, you will have a new button on the FlowLayoutPanel control.

Wish this can help you.

Sincerely,

Kira Qian

Kira Qian  Wednesday, October 22, 2008 3:02 AM

You can use google to search for other answers

Custom Search

More Threads

• Windows Form with User control and Tab Index / Tab Stop Help
• TabControl behaving strangly
• Is it possible expose all properties of user control with a little work
• Track the Shift Tab key in Textbox
• to know the system date
• How can a group of changes be merged into a single undoable action in the VS designer?
• Combo box with treeview
• HTML Help Display Location and Size
• Painting problems
• The designer could not be shown for this file because none of the classes within it can be designed.