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 |