How to create a certain number of buttons / labels 
Author Message
 How to create a certain number of buttons / labels

I need my function to create some buttons and labels, the number
depending on an integer variable the user will enter. So if the user
enters 55, I need 55 buttons created.

I know how to create, set properties and place a single button but I
don't know how to declare an ARRAY OF BUTTONS or labels.

This question concerns VB.net

thanks

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 03:21:30 GMT  
 How to create a certain number of buttons / labels
Hi Tim,

Here is some sample code that creates an array of buttons

Public Class Form2

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

<System.Diagnostics.De{*filter*}StepThrough()> Private Sub InitializeComponent()

Me.Button1 = New System.Windows.Forms.Button()

Me.TextBox1 = New System.Windows.Forms.TextBox()

Me.SuspendLayout()

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(88, 88)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 0

Me.Button1.Text = "Button1"

'

'TextBox1

'

Me.TextBox1.Location = New System.Drawing.Point(64, 56)

Me.TextBox1.Name = "TextBox1"

Me.TextBox1.TabIndex = 1

Me.TextBox1.Text = "TextBox1"

'

'Form2

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1,
Me.Button1})

Me.Name = "Form2"

Me.Text = "Form2"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim NumBtn As Integer = TextBox1.Text

Dim NewBtns(NumBtn) As Button

Dim i As Integer = 1

For i = 1 To NumBtn

Dim b As Button = NewBtns(i)

b = New Button()

b.Text = "MyBtn " & i

Me.Controls.Add(b)

b.Top = 100 + i * 25

Next

End Sub

End Class

Thanks
Robin & Mohan
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> I need my function to create some buttons and labels, the number
> depending on an integer variable the user will enter. So if the user
> enters 55, I need 55 buttons created.

> I know how to create, set properties and place a single button but I
> don't know how to declare an ARRAY OF BUTTONS or labels.

> This question concerns VB.net

> thanks

> *** Sent via Developersdex http://www.*-*-*.com/ ***
> Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 04:06:29 GMT  
 How to create a certain number of buttons / labels

Quote:
> I need my function to create some buttons and labels, the number
> depending on an integer variable the user will enter. So if the
> user enters 55, I need 55 buttons created.

> I know how to create, set properties and place a single button
> but I don't know how to declare an ARRAY OF BUTTONS or labels.

> This question concerns VB.net

You've already asked that today and it's been answered by three
replies.

Armin



Mon, 27 Dec 2004 04:23:34 GMT  
 How to create a certain number of buttons / labels

Quote:
>You've already asked that today and it's
>been answered by three replies.

Sorry, Google was sending me some HTTP500s so I thought the question
wasn't posted at all. I've switched to another news service now and I
won't be having the same problems.

rgds

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 06:38:22 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Creating Sequential Numbering in Labels

2. macro to create specified number of labels

3. How can I create button label?

4. How to create any number of buttons

5. Duplicating labels for certain records in a report

6. Number of certain records problem...

7. Breaking a field using textstream at certain column number (73)

8. how to make an autonumber field starting from a certain number

9. Creating Successive Numbers (Order Numbers)

10. procedure to find certain files from a certain date on harddisk

11. create popup when choosing certain distribution list

12. create popup when choosing certain distribution list

 

 
Powered by phpBB® Forum Software