Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to create a win form.In it there is a label which by default is not visible. Based on a condition i am setting its visibility to true. But one issue is there.


If i run the program without debugging am not able to see the label.
But when i debug to the place where i change the visibility property and then hit F5 , i am able to see. Weird rt??? please help me

THis is the code

C#
if (_dtWorkitems != null && _dtWorkitems.Rows.Count > 0)
              {
                  pgBar.Minimum = 1;
                  pgBar.Maximum = _dtWorkitems.Rows.Count;
                  pgBar.Step = 1;
                  pgBar.Visible = true;
                  txtMsg.Visible = true;
              }




The condition was that if a data table is not null then i am changing the visibility. Then i am looping the datatable . At the end i am changing the property of the label & progressbar back to false. I tried commenting that and the label was shown after exiting the loop. Why
Posted
Updated 7-Apr-14 1:25am
v3
Comments
Nagaraj Muthuchamy 7-Apr-14 6:56am    
Are you setting the property in Form_Load function ?

Posting the code here can help to understand the problem better.
Arjun Menon U.K 7-Apr-14 7:01am    
I am setting this property on Button click. What puzzles me is that it works for Progress bar, then y not for txtbox or label
ZurdoDev 7-Apr-14 7:23am    
What is the property set to in design view and then put a breakpoint and make sure your code is actually running the part where it gets set visible.
Arjun Menon U.K 7-Apr-14 7:32am    
Did you see the code i posted above. I am setting the visibility of both label & progress bar in that if statement and its working for pgbar nd not for label,provided am not debugging it :'(

1 solution

try calling invalidate or update or something. that should force a redraw.
If you leave the label visible from the start. is it there then?
 
Share this answer
 
v2
Comments
Arjun Menon U.K 7-Apr-14 7:27am    
Then y its working for progress bar?
V. 7-Apr-14 7:33am    
progress bar is a different control from the rest because it needs to update itself based on values. So it has som form of an inherent redraw. I had similar problems when using label updates simultaneously with progress bar updates.
Is the solution working then, or not?
Arjun Menon U.K 7-Apr-14 7:56am    
Hi , it worked when i called Update(). Thanks a lot. But my question is why it works while debugging, from what you have said it means that debugging causes the control to redraw. Correct me if i am wrong. The visible setting to false works without the update function which puzzles me more
V. 7-Apr-14 8:07am    
That is a common issue. I always blame it on internal timing issues dus to optimizations for "release" compilation, but the truth is, I don't know. I just know that in some occasions there is a difference.
Glad it worked.
Arjun Menon U.K 7-Apr-14 8:11am    
:) thanks buddy

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