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

i do have the problem, if i try to set the visibility of my Form to false.

if the form is in FormWindowState = Normal, everything is working as expected.
but if i try it in FormWindowState = Maximized, it will cause the problem, that programmatically my form is visible = false, but will be about half a second later.


does anyone knows this problem?
and more important, does anyone knows a solution? :D


Here my code to set the visibility:
C#
private void notifyIcon_DoubleClick(object Sender, EventArgs e)
{
   if (!allowshowdisplay)
   {
      this.Left = Screen.PrimaryScreen.WorkingArea.Width / 2 - Width / 2;
      this.Top = Screen.PrimaryScreen.WorkingArea.Height / 2 - Height / 2;
   }

   if (!this.Visible)
   {
      SplashScreen.ShowSplashScreen(new Rectangle { Size = this.Size, Location = this.Location }, @"\Resources\wait.jpg", false);

      Thread.Sleep(100);
   }

   this.allowshowdisplay = true;
   this.Visible = !this.Visible;

   if (this.Visible)
      SplashCloseThreaded();
   else
      SplashScreen.CloseForm();
}
Posted
Updated 18-Sep-14 3:33am
v3
Comments
BillWoodruff 18-Sep-14 6:09am    
Need more information: how many Forms are there; which/what is the Main Form. What does 'SplashCloseThreaded do ?
Nooa 18-Sep-14 6:17am    
this is the MainForm.
At this moment is only one Form active (this MainForm)
SplashCloseThreaded closes the SplashScreen with an separate delay.
the SplashScreen is an own thread, but is in this moment not active.
BillWoodruff 18-Sep-14 6:40am    
See if this makes any difference in performance:

if (this.Visible)
this.Hide();
SplashCloseThreaded();
else
this.Show();
SplashScreen.CloseForm();

You might want to show the code for 'SplashScreen CloseForm and ShowSplashScreen.
Nooa 18-Sep-14 7:44am    
doesnt make any difference

Quick test (Add a button to an existing form, set Visible to false in the button) says there is no significant time difference between hiding a "normal" form and a maximized one.
So...the problem has to be in your subsequent methods, and pretty much has to be that they are taking the time - which means that the visibility request is not honoured visually until the method exits, and that's what I would expect. The single thread can't do two things at the same time.
Depending on what your methods are doing, it may be possible to move them to a background thread, or in extreme cases add a timer which "delays" calling the method until the form is actually hidden.
 
Share this answer
 
Comments
Nooa 18-Sep-14 7:45am    
@Button:
problem is still active with the button, but at the 2nd press, the form is invisible...

so it has to be a problem in my sequence...


thanks
You code snippet is incomplete.

I have no idea what allowshowdisplay is for.

Why you're calling Thread.Sleep, which, BTW, will cause your UI to freeze and not update at all during that time.

What is the SplashCloseThreaded? Why "threaded"?

What is this??


Remember, your windows and controls will NOT update themselves on screen when the individual statements manipulating them are executed. The UI thread (startup thread) cannot respond to the incoming WS_PAINT events until your DoubleClick event handler is done executing.
 
Share this answer
 
Comments
Nooa 18-Sep-14 9:25am    
hi, the sleep is set to give the splashscreen time to build up and hide the MainForm to workaround a flicker of it, until it is hidden by the splash
Dave Kreskowiak 18-Sep-14 9:55am    
You're not giving it time to build up. You're actually preventing it from painting because you put the UI thread to sleep.
i solved the problem.

issue was a "this.ShowInTaskbar = this.Visible" in "Form_VisibleChanged"

so since i commented this line, everything is working as expected.
 
Share this answer
 

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