C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Application windows, menus & toolbars »

Generation of controls in Vb.net


Posted Date: 25 Jul 2009    Resource Type: Code Snippets    Category: Application windows, menus & toolbars
Author: NeetuMember Level: Diamond    
Rating: 1 out of 5Points: 7



description :


It is basically used to generate runtime controls using vb.net.
User has to enter number for the labels and textboxes. as soon as he click on the button. He will get that number of labels with proper formatting and alignment.


Public Class Form1
Dim ob() As Label
Dim ob1() As TextBox
Dim i As Integer
Dim y As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Panel1.Controls.Clear()
y = 10
If Val(TextBox1.Text) = Val(TextBox2.Text) Then

ReDim ob(Val(TextBox1.Text) - 1)
ReDim ob1(Val(TextBox1.Text) - 1)

For i = 0 To Val(TextBox1.Text) - 1
ob(i) = New Label
ob(i).Name = "lbl" & i
ob(i).Text = "Test" & i
ob(i).Size = New Size(50, 20)
ob(i).Location = New Point(10, y)
Panel1.Controls.Add(ob(i))

ob1(i) = New TextBox
ob1(i).Text = "Neet " & i
ob1(i).Size = New Size(150, 30)
ob1(i).Location = New Point(80, y)
Panel1.Controls.Add(ob1(i))
y = y + 30
'ob = Nothing
'ob1 = Nothing
Next
Else
MsgBox("WRONG ENTRY")
End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class

Public Class Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Label1.Visible Then
Label1.Visible = False
Else
Label1.Visible = True
End If
End Sub
End Class


Regards.
Neetu

Attachments

  • Runtime Generation of controls in VB.NET (30741-25422-GENERATING CONTROLS.rar)


  • Responses

    Author: Miss Meetu Choudhary    25 Jul 2009Member Level: Diamond   Points : 1
    Please Add some description to the resource


    ++
    Thanks and Regards.
    Meetu Choudhary.
    Site Coordinator.




    Author: Deepika Haridas    25 Jul 2009Member Level: Diamond   Points : 2
    Hi,

    Don't just attach code. You must also post it. I have currently done for this post and also formatted your post. Hope from next time onwards you will take care of all these things.

    ---
    Thanks & Regards,
    Deepika
    Editor


    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Very useful for runtime generation of controls  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Dynamic controls through SQL Server using VB.Net
    Previous Resource: Graphics - Bouncing,Shrinking and Rotating Balls
    Return to Discussion Resource Index
    Post New Resource
    Category: Application windows, menus & toolbars


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use