swapping controls within a form

  • Thread starter Thread starter cwineman
  • Start date Start date
C

cwineman

Hello,

Maybe someone here can tell if/how something is possible. I want to have a
form, with a place-holder panel. In that place-holder panel I will
temporarily place different controls as conditions change in my application.

For example, at the beginning of the program, controlA would be in the place
holder. Upon some event, I want to stick controlB in the place-holder panel,
let it display for a few seconds, then replace controlB with controlA in the
place-holder.

I've included some code below so people can see how I am try to do this, but
I don't think it will work. I think the problem has to do with updating the
UI from a non-UI thread. Unfortunately, I don't know the correct way.

Can anyone help me out here? Or send a link to examples of something
similar?

-cwineman

private void updatePlaceHolderPanel( string messageString )

{

ControlB controlB = new ControlB();

controlB.MessageString = messageString;


placeHolderPanel.Controls.Remove( controlA );

placeHolderPanel.Controls.Add( controlB );

Console.WriteLine("Before Pause");

//dramatic 4 second pause

Thread.Sleep( 4000 );

Console.WriteLine("After Pause");


placeHolderPanel.Controls.Remove( controlB );

placeHolderPanel.Controls.Add( controlA );

}
 
Hi cwineman,

I'm guessing that the panel never manages to load controlB before the
thread sleeps.
You could also try to simply hide controlA and show controlB instead of
removing/adding.
 
Back
Top