Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I have 5 Labels on the same location and I want to make one visible
and the others invisible.

and switch between theme.

Any Help Thank you.

What I have tried:

LabelMatchGroupCapture.Visible = False
     LabelMatchGroup.Visible = False
     LabelMatch.Visible = False
     ReplaceLabel.Visible = False
     SplitLabel.Visible = False

     If xn = 3 Then
         LabelMatchGroupCapture.Visible = True
     ElseIf xn = 2 Then
         LabelMatchGroup.Visible = True
     Else
         LabelMatch.Visible = True
     End If
Posted
Updated 27-May-20 22:43pm
Comments
RickZeeland 28-May-20 4:04am    
Your code looks ok, what is the problem?
What do you mean with theme, skinning Winforms maybe?
Member 13569650 28-May-20 4:21am    
Hi RickZeeland

The problem is that this code is
inside a sub that takes some seconds of processing.
and in that time no labels appears.
and only in finishing process
the one label chosen appear
and I want that one label be
visible at any time.

I put this code before the lengthy process.
Member 13569650 28-May-20 6:01am    
I got it
I will make one label only
and each Time I will change
its text with the required text.

Thank you.
RickZeeland 28-May-20 6:23am    
Knew you could do it :)

In addition to make one visible, you have to make the four others invisible as well.

A better solution to the if..else spaghetti code would be to have the labels in an array, and define a function to make the label with specified index visible (implying the four others labels invisible).
C#
private void MakeVisible(int index)
{
   for (int i = 0; i < theLabelArray.Length; ++i)
   {
      theLabelArray[i].Visible = (i == index);
   }
}
 
Share this answer
 
v2
Comments
Member 13569650 28-May-20 5:01am    
The code makes the four others invisible.
Maciej Los 28-May-20 5:14am    
It does exactly what you mentioned in your quesiton.
phil.o 28-May-20 5:20am    
Your reply to Rick's comment does not exactly fit your original question. Without deeper context, it is not obvious that all labels are made invisible each time before one of them is set visible.
Maciej Los 28-May-20 5:14am    
5ed!
phil.o 28-May-20 5:17am    
Thanks Maciej :)
As your problem seems to be in some time consuming code, you might put this code in a separate Task, see: Visual Basic Task - Tutlane[^]
So first update your labels, and then run the Task.

Beware that the mentioned example is very simple, as soon as you want to do things in the GUI e.g. change a label, things become more complicated and you should use InvokeRequired or something similar.
vb.net - What does 'InvokeRequired' and 'Invoke' mean in .Net? - Stack Overflow[^]
 
Share this answer
 
v2
Comments
Member 13569650 28-May-20 5:07am    
I don't think so.
I think that
the order in which the labels
are maked visible/invisible is
the matter because with some
playing with the order I got
some solution but not full solution.
RickZeeland 28-May-20 5:45am    
As I can't see your "time consuming code" there is not much I can do about it I'm afraid ...
Member 13569650 28-May-20 5:51am    
This order of visible/invisible for example
give me a close solution
only one label the big one appear partialy ==> "MatchesGroupsC"
the labels are

Me.LabelMatchGroupCapture.Text = "MatchesGroupsCaptures Results"
Me.LabelMatchGroup.Text = "MatchesGroups Results"
Me.LabelMatch.Text = "Matches Results"
Me.ReplaceLabel.Text = "Replace Results"
Me.SplitLabel.Text = "Split Results"

So its the matter of order (How to find the right order)


If xn = 3 Then
list2array = sMatchesGroupsCaptures.ToArray
tlist2array = vMatchesGroupsCaptures.ToArray
LabelMatchGroupCapture.Visible = True
LabelMatch.Visible = False
LabelMatchGroup.Visible = False
ReplaceLabel.Visible = False
SplitLabel.Visible = False
ElseIf xn = 2 Then
list2array = sMatchesGroupsList.ToArray
tlist2array = vMatchesGroupsList.ToArray
LabelMatchGroup.Visible = True
LabelMatch.Visible = False
LabelMatchGroupCapture.Visible = False
ReplaceLabel.Visible = False
SplitLabel.Visible = False
Else
list2array = sMatchesList.ToArray
tlist2array = vMatchesList.ToArray
LabelMatch.Visible = True
LabelMatchGroup.Visible = False
LabelMatchGroupCapture.Visible = False
ReplaceLabel.Visible = False
SplitLabel.Visible = False
End If
RickZeeland 28-May-20 5:58am    
That sounds like you have a problem with the TAB order of the controls, see: https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-set-the-tab-order-on-windows-forms

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900