Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,183 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,788 people online right now. Registration is fast and FREE... Join Now!





Create Control Arrays at runtime in VB 2005 with Events

This code will add number of nuppe buttons in a panel. When you click any of the button, it will tell his number with msgbox. This snippet can be used as an example of verios things

Submitted By: m2s87
Actions:
Rating:
Views: 12,266

Language: VB.NET

Last Modified: January 21, 2007

Snippet


  1.     '
  2.     'Written by Margus Martsepp aka m2s87
  3.     '   
  4.     Const Nuppe As Integer = 20
  5.     Dim Nupud(Nuppe) As Button
  6.     Dim Nupp As Button
  7.  
  8.     Private Sub Form1_Load(ByVal sender As System.Object, _
  9.     ByVal e As System.EventArgs) Handles MyBase.Load
  10.         '
  11.         'Panel1
  12.         '
  13.         Dim Panel1 As New System.Windows.Forms.Panel
  14.         Panel1.Parent = Me
  15.         Panel1.AutoScroll = True
  16.         Panel1.Location = New System.Drawing.Point(12, 12)
  17.         Panel1.Name = "Panel1"
  18.         Panel1.Size = New System.Drawing.Size(152, 235)
  19.         Panel1.TabIndex = 2
  20.         '
  21.         'Nupud
  22.         '
  23.         Const laius As Integer = 120
  24.         Const kõrgus As Integer = 25
  25.  
  26.         For i As Integer = 1 To Nuppe
  27.             Nupp = New Button
  28.             Nupp.Parent = Panel1
  29.             Nupp.Size = New Size(laius, kõrgus)
  30.             Nupp.Text = CType(i, String)
  31.             Nupp.Top = CType((i - 1) * 30, Integer)
  32.             Nupp.BackColor = Color.Blue
  33.             Nupp.Visible = True
  34.             AddHandler Nupp.Click, AddressOf Nupp_Click
  35.             Nupud(i) = Nupp
  36.         Next i
  37.  
  38.     End Sub
  39.  
  40.     Private Sub Nupp_Click(ByVal sender As System.Object, _
  41.     ByVal e As System.EventArgs)
  42.         MsgBox("You clicked on button: " & CType(sender.Text, String))
  43.     End Sub

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month