hello everyone.
i have 8 labels on a page and i have to select them one ba one.
all the labels are selected ba the user one after the other from top to bottom fashion,
like firstly label1 is selected then label2........labeln
and if someone exploits this fashion i want to show an error message please select label 1 before label2.
thanx in advance......

and you have tried....?

8 fixed lables? are you putting them in Panel or gropu box?
And what are the names you have given them to identify the sequence?

yes 8 fixed labels..
i am putting them in a form.

What is the name u gave to the label to identify?

See if this helps you... you need to give the propernames what you gave in design.

Private Sub Label3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label3.Click, Label4.Click, Label5.Click, Label6.Click
        Dim blblclick1 As Boolean
        Dim blblclick2 As Boolean
        Dim blblclick3 As Boolean
        Dim blblclick4 As Boolean


        Select Case sender.name.ToString
            Case "Label1"
                blblclick1 = True
            Case "Label2"
                If blblclick1 = False Then
                    MessageBox.Show("Please click label 1 first")
                End If
            Case "Label3"
                If blblclick2 = False Then
                    MessageBox.Show("Please click label 2 first")
                End If
            Case "Label4"
                If blblclick3 = False Then
                    MessageBox.Show("Please click label 3 first")
                End If
            Case "Label5"
                If blblclick4 = False Then
                    MessageBox.Show("Please click label 4 first")
                End If


        End Select

    End Sub

Here is the code you want. It check all the possibilities.
Let me know what you think:

Private labelClicked As Integer
Public Sub New()
	InitializeComponent()
	Dim labels As Label() = {label1, label2, label3, label4, label5, label6, _
		label7, label8}
	For i As Integer = 0 To labels.Length - 1
		labels(i).Tag = i
		labels(i).Click += New EventHandler(AddressOf Labels_Click)
	Next
End Sub

Private Sub Labels_Click(sender As Object, e As EventArgs)
	Dim l As Label = TryCast(sender, Label)
	Dim currentTag As Integer = CInt(l.Tag)
	If labelClicked < 8 Then
		If labelClicked <> currentTag Then
			If labelClicked < currentTag Then
				MessageBox.Show([String].Format("Please select label{0} before label{1}.", (labelClicked + 1), (currentTag + 1)))
			Else
				MessageBox.Show([String].Format("Label{0} has already been selected.", (currentTag + 1)))
			End If
		Else
			labelClicked += 1
			'color selected label for example:
			l.ForeColor = Color.Red
			If labelClicked.Equals(8) Then
				MessageBox.Show("All labels are selected now.")
			End If
		End If
	Else
		MessageBox.Show("You have already selected all the labels.")
	End If
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.