hello friends,
i am developing a windows application in which user has to answer 180 questions,through clicking on the labels defined in the windows,
the problem which i am facing is, if the user redirects the form to another page and when comes back,
i want that the previous choices clicked ba the user is visible to him when he browses back to the previous form.
p.s when one selects the lable then the color of the label changes to black and the non selected labels are still in white colors.....i want that color to remain once the user comes back.
thanks in advance.

Recommended Answers

All 10 Replies

... the problem which i am facing is, if the user redirects the form to another page and when comes back,
i want that the previous choices clicked ba the user is visible to him when he browses back to the previous form.

Does that means you close this form (when redirecting)?
If so, you create a property on some class, which will remember (using SET modifier) the question the user was answering for the last time.
So, when comming back to this question form, you read that property (using Get access modifier) and then set the lablels by it.
You know what I mean?

Hi mitja,
I have a doubt here... if Questions are in more say 100+ then ?

It really doesnt matter how many labels there are.
Are these question being answred one after another (in an order), or can be answered with no order?

Ok, I did a code, which uses its own class, and a property. Property is a generic list, type of Label. So into this property are saving clicked labels (using SET access modifier), and when you want to show already clicked lables, the code uses GET access modifer to set appropriate labels (their forecolor proiperty).

I was thinking that this Labels are on Form2 (which is opened from Form1), so when re-opening a form2, it will automatically set label which have been clicked before.
If none clicked, of form2 is opened for the 1st time, will happen nothing.

So, heres the code:

Public Partial Class Form2
	Inherits Form
	Private labels As Label()
	Public Sub New()
		InitializeComponent()

		labels = New Label(5) {}
		Dim x As Integer = 20, y As Integer = 20
		For i As Integer = 0 To labels.Length - 1
			labels(i) = New Label()
			labels(i).Name = "label" & i
			labels(i).Location = New Point(x, y)
			labels(i).Text = GetQuestions(i)
			'this is my own way of creating questions...
			labels(i).Click += New EventHandler(AddressOf Labels_Click)
			labels(i).Tag = i
			labels(i).ForeColor = Color.Black
			Me.Controls.Add(labels(i))
			y += 25
		Next
		If Questions.myLabels Is Nothing Then
			Questions.myLabels = New List(Of Label)()
		End If

		'setting forecolor to already clicked questions:
		For Each l As Label In Questions.myLabels
			Dim _tag As Integer = CInt(l.Tag)
			labels(_tag).ForeColor = Color.Red
		Next
	End Sub

	Private Function GetQuestions(i As Integer) As String
		Dim question As String = ""
		Select Case i
			Case 0
				question = "Question 1"
				Exit Select
			Case 1
				question = "Question 2"
				Exit Select
			Case 2
				question = "Question 3"
				Exit Select
			Case 3
				question = "Question 4"
				Exit Select
			Case 4
				question = "Question 5"
				Exit Select
			Case 5
				question = "Question 6"
				Exit Select
		End Select
		Return question
	End Function

	Private Sub Labels_Click(sender As Object, e As EventArgs)
		Dim l As Label = TryCast(sender, Label)
		If l.ForeColor = Color.Black Then
			l.ForeColor = Color.Red
			'
			'add label to the list (which holds already selected questons):
			'you can add it to the list after the question has been answered too!!
			Questions.myLabels.Add(l)
		Else
			MessageBox.Show("This question has been already answered.")
		End If

	End Sub
End Class

Public NotInheritable Class Questions
	Private Sub New()
	End Sub
	Public Shared Property myLabels() As List(Of Label)
		Get
			Return m_myLabels
		End Get
		Set
			m_myLabels = Value
		End Set
	End Property
	Private Shared m_myLabels As List(Of Label)
End Class

Hope it helps,
bye

btw, the code above creates only 6 label. You will create 180 (or what ever). These labels are created all in a run time, so nothing in needed just a clear form2 (nothing on it).
Be careful on Location property of each label, I position labels no one under another - you can do it differently (depends on your needs).

bye

thanks for such a warm response.
people i have to answer the labels one after the other and also i have not closed the form, i have hide the previous form and opened the other form....
any help would be appreciated.
regards
aditya:)

You could try using session variables. In larger applications you need to be careful with them, but storing 180 questions plus the color should be fine.

Just do something like session("QuestionOne") = -TheirQuestionOneAnswer-

is it web or windows? at very first post aadi mentioned as windows and in windows we will not have Sessions

pgmer:- yes you are right.
its a windows form.
Is there any alternative for that?

guys i have to submit the project day after please help me out with this one.

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.