Add textbox to the panel for each buton click

venky

Active member
Joined
Sep 12, 2005
Messages
27
Programming Experience
1-3
Hi


My task :

I want to add new textbox to the exixting panel for each click on the button.

Error :

For add new textbox the previous textbox was disappear.


Please help me how can reach my target.
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
VB.NET:
Private sub Button1_click(blah blah blah) handles button1.click
 
Dim Tb as new textbox
tb.size = new size......
me.panel.controls.add(tb)
tb.location  = new point(....)
end sub
 

BadgerByte

Well-known member
Joined
Aug 5, 2005
Messages
194
Location
Ipswich, UK
Programming Experience
5-10
Hey venky,

Something like this should work, for this example place a Panel on your form with autoscroll set to true.

VB.NET:
Public Class Form1
    Inherits System.Windows.Forms.Form

    Private HSpacing As Integer = 10
    Private VSpacing As Integer = 40
    Private BoxWidth As Integer = 200
    Private MaximumBoxes As Integer = 20
    Private NumberOfBoxes As Integer = 0

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If NumberOfBoxes < MaximumBoxes Then
            Dim TempTextBox As New TextBox

            TempTextBox.Name = "MyTextBox" & NumberOfBoxes.ToString

            Panel1.Controls.Add(TempTextBox)
            TempTextBox.Width = BoxWidth
            TempTextBox.Top = (NumberOfBoxes * VSpacing) + Panel1.AutoScrollPosition.Y
            TempTextBox.Left = HSpacing
            TempTextBox.Visible = True

            NumberOfBoxes += 1
        End If

    End Sub
End Class
Hope this helps,

Regards,

Andy

[edit] Sorry Vis781, I didn't realise you'd already answered!
 

venky

Active member
Joined
Sep 12, 2005
Messages
27
Programming Experience
1-3
Thq

But, It is working fine in the case of vb.net .I want to add the controls dynamic in the ASP.net.Today also i was tried so much to get this.Ever time new control was add but the old control was not a there.
 
Top Bottom