khalik Posted January 24, 2003 Posted January 24, 2003 hi this is my first post in this forums... hope it get answerd soon.. can we load controls dymanic as we do in vb6. and position them. and is this possible in asp.net Quote
Moderators Robby Posted January 24, 2003 Moderators Posted January 24, 2003 Since this was in Windows Forms, here's an example.... Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim btn As New Button() Dim i As Integer For i = 1 To 10 btn = New Button() With btn AddHandler .Click, AddressOf btnClick .Text = "button " & i .Location = New Point(0, i * 60) .Size = New Size(100, 50) End With Controls.Add(btn) Next End Sub Private Sub btnClick(ByVal sender As Object, ByVal e As EventArgs) MessageBox.Show("You clicked ... " & DirectCast(DirectCast(sender, Button).Text, String)) End Sub Quote Visit...Bassic Software
Moderators Robby Posted January 24, 2003 Moderators Posted January 24, 2003 For ASP... 'top of page, inside your class... Private Panel1 As New System.Web.UI.WebControls.Panel() Private PlaceHolder1 As New System.Web.UI.WebControls.PlaceHolder() Private button1 As New System.Web.UI.WebControls.Button() Private label1 As New System.Web.UI.WebControls.Label() 'inside your Page_Load event... Controls.Add(PlaceHolder1) PlaceHolder1.Controls.Add(Panel1) Panel1.Controls.Add(label1) Panel1.Controls.Add(button1) 'then you can format the controls once they are added to the form Quote Visit...Bassic Software
Threads Posted February 4, 2003 Posted February 4, 2003 Thanks, Robby. This is exactly what I was looking for. I'm creating a new app for .NET using an old program concept I had and I needed the ability to add more controls when needed. One question though, is what is a good method to later destroy them if not needed? For example, if the form only needs 5 at one time, then the user adds more by setting option, then decides they only really need 3 now, is there an easy way to identify the ones added to destroy? Quote mov ax, 13h int 10h
Moderators Robby Posted February 4, 2003 Moderators Posted February 4, 2003 you can use Controls.Removeat() or Controls.Remove(label1) Or even the child of a container Panel1.Controls.Remove(label1) Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.