Hello Try using something like below
Regards
Ola
Try using a class
Public Const cnLabelName As String = "LBL"
Public Class My_Label
Inherits Windows.Forms.Label
Dim iFieldIndex As Integer = 0
Private Sub My_Label_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
'
'Get the index of the label clicked
iFieldIndex = CInt(Mid(Me.Name, Len(cnLabelName) + 1))
'
End Sub
End Class
'Label creating class
Private My_Label() As My_Label
Dim NoOfLabelsNeeded as integer = 100
For I = 1 to NoOfLabelsNeeded
ReDim Preserve My_Label(i)
My_Label(i) = New My_Label()
With My_Label(i)
.Name = cnLabelName & i
.Location = New
System.Drawing.Point(iLabelXPosition, YPosition)
.BackColor = System.Drawing.Color.Transparent
.Font = fFont
.Visible = True
.Width = iLabelWidth
bPreviousYPositionUsed = True
If fdFields(i).bShowInSingleRecord = False Then
.Visible = False
.Location = New System.Drawing.Point(0, 0)
bPreviousYPositionUsed = False
End If
End With
Next
-----Original Message-----
From: Lester, Simon [mailto:Simon.Lester@c...]
Sent: dinsdag 23 juli 2002 14:35
To: professional vb
Subject: [pro_vb] RE: Click event of dynamic labels
Make the labels a dynamic array which you can add to at runtime. That
way
they will share events.
-----Original Message-----
From: Alex Read [mailto:aread@b...]
Sent: 23 July 2002 15:41
To: professional vb
Subject: [pro_vb] Click event of dynamic labels
Hard one this! ;c)
I've got a bit of code on a form which creates 100 dynamic labels (named
lbl1 through to lbl100), and they're created using the withevents
keyword.
Is there any way to recognise if one of these was clicked, i.e. rather
than using:
Private sub lbl1_click() ....
End sub
Is there a way I could say "If one of my labels from lbl1 to lbl100 was
clicked, return the name of this label in a messagebox" type of thing?
Thanks All!
---
Visual C# - A Guide for VB6 Developers
This book will make it easy to transfer your skills
from Visual Basic 6 to C#, the language of choice
of the .NET Framework.
http://www.wrox.com/ACON11.asp?ISBN=1861007175&p2p0059
THIS E-MAIL AND ANY ATTACHED FILES ARE CONFIDENTIAL AND MAY BE LEGALLY
PRIVILEGED. If you are not the addressee, any disclosure, reproduction,
copying, distribution or other dissemination or use of this
communication is
strictly prohibited. If you have received this transmission in error
please
notify the sender immediately and then delete this e-mail.
Opinions, advice or facts included in this message are given without any
warranties or intention to enter into a contractual relationship with
the
Corporation of London unless specifically indicated otherwise by
agreement,
letter or facsimile signed by an authorised signatory of the
Corporation.
Any part of this e-mail which is purely personal in nature is not
authorised
by the Corporation of London. All e-mail through the Corporation's
gateway
is potentially the subject of monitoring.
All liability for errors and viruses is excluded.
---
Visual C# - A Guide for VB6 Developers
This book will make it easy to transfer your skills
from Visual Basic 6 to C#, the language of choice
of the .NET Framework.
http://www.wrox.com/ACON11.asp?ISBN=1861007175&p2p0059