473,326 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How can I make an array of Label ?

I try to make an array of label as this.

Dim ArrLabel(10) as System.Windows.Forms.Label
For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()

Next

But it didn't show on the form. Can you help me plz.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #1
13 1707

"Lighting_dragon" <as*@asd-dot-com.no-spam.invalid> wrote in message
news:40********@Usenet.com...
I try to make an array of label as this.

Dim ArrLabel(10) as System.Windows.Forms.Label
For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()
Next

But it didn't show on the form. Can you help me plz.


arrLabel(i).Visible = True ???

Also, doesn't .Net dim starting from 0, meaning Dim ArrLabel(10) = 0 through
9... ArrLabel(10) would error?
Nov 20 '05 #2
* as*@asd-dot-com.no-spam.invalid (Lighting_dragon) scripsit:
I try to make an array of label as this.

Dim ArrLabel(10) as System.Windows.Forms.Label

For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
\\\
Me.Controls.Add(ArrLabel(i))
///
Next

But it didn't show on the form. Can you help me plz.


--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
add the control useing me.controls.add(arrLabel(i)) and make sure you make
it visible
arrLable(i).visible = true
don't use .Show
"Lighting_dragon" <as*@asd-dot-com.no-spam.invalid> wrote in message
news:40********@Usenet.com...
I try to make an array of label as this.

Dim ArrLabel(10) as System.Windows.Forms.Label
For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()

Next

But it didn't show on the form. Can you help me plz.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 20 '05 #4
Hi,

Control array control.
http://www.windowsforms.com/default....mID=16&mid=142

Ken
------------------

"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:O0**************@TK2MSFTNGP11.phx.gbl:
add the control useing me.controls.add(arrLabel(i)) and make sure you make

it visible
arrLable(i).visible = true
don't use .Show
"Lighting_dragon" <as*@asd-dot-com.no-spam.invalid> wrote in message
news:40********@Usenet.com...
I try to make an array of label as this.

Dim ArrLabel(10) as System.Windows.Forms.Label
For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()

Next

But it didn't show on the form. Can you help me plz.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
HYPERLINK "http://www.usenet.com"http://www.usenet.com


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004
Nov 20 '05 #5
add the control useing me.controls.add(arrLabel(i)) and make sure you make
it visible
arrLable(i).visible = true
don't use .Show


Thats interesting, Ive never struck that before. Whats the difference (other
than method and property) between the 2 uses?

Thanks
Richard
Nov 20 '05 #6
-----Original Message-----
I try to make an array of label as this.

Dim ArrLabel(10) as System.Windows.Forms.Label
For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()

Next
But it didn't show on the form. Can you help me plz.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
---------------------------------------------------------- http://www.usenet.com
.
You forgot to bind the label to a form .....

ArrLabel(i).Text="Test" & i
Me.Controls.Add(ArrLabel(i))

You don't need the Show Statement
.............
Nov 20 '05 #7
Grahammer,
Also, doesn't .Net dim starting from 0, meaning Dim ArrLabel(10) = 0 through 9... ArrLabel(10) would error? Welcome to the VB.NET "off by one bug"! :-)

..NET arrays do start with 0! VB.NET lists the upper bound, not number of
elements in array definitions. So
Dim ArrLabel(10) as System.Windows.Forms.Label


Has elements 0 to 10!

Hope this helps
Jay

"Grahammer" <do*******@me.here> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
"Lighting_dragon" <as*@asd-dot-com.no-spam.invalid> wrote in message
news:40********@Usenet.com...
I try to make an array of label as this.

Dim ArrLabel(10) as System.Windows.Forms.Label
For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()
Next

But it didn't show on the form. Can you help me plz.
arrLabel(i).Visible = True ???

Also, doesn't .Net dim starting from 0, meaning Dim ArrLabel(10) = 0

through 9... ArrLabel(10) would error?

Nov 20 '05 #8
Thanks for all your help.
I have made a mistake with the array(10), only form 0 -->9.
Then I have add the Method Me.Controls.Add(arrlabel(x))

Now it works well.

But I have a problem. How can I write a Sub to control the Event
Label.OnClick of all the Labels in Array.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #9
Lighting_dragon,
You can use AddHandler & RemoveHandler to add a sub as an event handler to
each element.

Something Like:

For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()
AddHandler ArrLabel(i).Click, Address Label_Click
Next

Public Sub Label_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Hope this helps
Jay

"Lighting_dragon" <as*@asd-dot-com.no-spam.invalid> wrote in message
news:40********@Usenet.com...
Thanks for all your help.
I have made a mistake with the array(10), only form 0 -->9.
Then I have add the Method Me.Controls.Add(arrlabel(x))

Now it works well.

But I have a problem. How can I write a Sub to control the Event
Label.OnClick of all the Labels in Array.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 20 '05 #10
I also have a need for this type of functionality, but on Web Forms

I have items that are variable in number that I wish to display on a web
form. And I would like to be able to specify or access the contents of
item(x) by referenced the x elements of that array/collection.

I have tried something like the following on the form load event but nothing
ever shows on the form.

Dim ArrLabel(10) As WebControls.Label
For x = 1 To 10
ArrLabel(x) = New WebControls.Label
ArrLabel(x).Visible = True
ArrLabel(x).Text = "Label "
Page.Controls.Add(ArrLabel(x))
Next
Any help or guidance is appreciated.

Fred
"ppap" <an*******@discussions.microsoft.com> wrote in message
news:18*****************************@phx.gbl...
-----Original Message-----
I try to make an array of label as this.

Dim ArrLabel(10) as System.Windows.Forms.Label
For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()

Next
But it didn't show on the form. Can you help me plz.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------

http://www.usenet.com
.
You forgot to bind the label to a form .....

ArrLabel(i).Text="Test" & i
Me.Controls.Add(ArrLabel(i))

You don't need the Show Statement
............

Nov 20 '05 #11
How would I do this with a Web form in a webapplication?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Lighting_dragon,
You can use AddHandler & RemoveHandler to add a sub as an event handler to
each element.

Something Like:

For i =0 to 10
ArrLabel(i) = New System.Windows.Forms.Label
ArrLabel(i).Left=25
ArrLabel(i).Top=25*i
ArrLabel(i).Name="Label" & i
ArrLabel(i).Text="Test" & i
ArrLabel(i).Show()
AddHandler ArrLabel(i).Click, Address Label_Click
Next

Public Sub Label_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Hope this helps
Jay

"Lighting_dragon" <as*@asd-dot-com.no-spam.invalid> wrote in message
news:40********@Usenet.com...
Thanks for all your help.
I have made a mistake with the array(10), only form 0 -->9.
Then I have add the Method Me.Controls.Add(arrlabel(x))

Now it works well.

But I have a problem. How can I write a Sub to control the Event
Label.OnClick of all the Labels in Array.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Nov 20 '05 #12
Hi Fred,

I think this sample does it all for you, this are buttons, however the
difference between a weblabel and a webbutton is very slight (it has
autopostback).

I hope this helps?

Cor

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim mybutton(31) As Button
Dim i As Integer
For i = 0 To New Date().DaysInMonth _
(New Date().Year, New Date().Month) - 1
mybutton(i) = New Button
mybutton(i).BackColor = Drawing.Color.White
mybutton(i).Text = (i + 1).ToString
mybutton(i).Width = New Unit(30)
Me.Panel1.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
If (i + 1) Mod 5 = 0 Then
Me.Panel1.Controls.Add(New LiteralControl("<BR>"))
End If
Next
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mylabel As New Label
Me.Panel1.Controls.Add(New LiteralControl("<BR><BR>"))
Me.Panel1.Controls.Add(mylabel)
mylabel.Text = "The day is: " & DirectCast(sender, Button).Text
End Sub
Nov 20 '05 #13
Hi Fred,

I forgot this.

Better is to make a new question next time, now it seems an answer to a
question to the OP (origianal poster).

Cor
Nov 20 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jhs | last post by:
Hello, I developping a .NET windows form application an need some help to create an array of System.Windows.Forms.Label in order to be able to manage all of them using index. I'm trying to do...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
1
by: GL | last post by:
I am trying to develop a prgram that randomly selects numbers for an addition program, then when the check answer button is pressed it colors the answer text field either green or red depending if...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
1
by: Neal | last post by:
I need to create many labels to fit on a windows forms and instead of using the designer to create a large number of text labels I just wanted to make an array of them and then loop through them to...
10
by: cbdeja | last post by:
I am using a "unsigned long long" as a label to identify various transactions that are taking place in my program. The label is reserved during the lifetime of the transaction and then released...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, Label lbls = {Label1, Label2, Label3}; i know you can iterate thru the elements, cast to Label object, and then set its visibility. But is there a way to set the elements all at once...
3
realin
by: realin | last post by:
Hiya all, i am in deep trouble, i thought it was an easy task, but now its getting on my nerves. Well i have a div on a form, which contains a number of checkboxes, as <div...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.