Hello Anand,
use SwitchToDialog(). It automatically replaces the actual dialog with a new one.
Each time we perform SwitchToDialog, it is overlaying these screens I believe.
It can occur when you invoke SwitchToDialog() in context of different GUI components. For example:
1. First you invoked SwitchToDialog( A, ... ) in context of the Application component.
2. Then being in A you invoked SwitchToDialog( B, ... ). This invocation is thus performed in context of the A component. The component B appears thus embedded inside A.
3. Later when you perform SwitchToDialog( A, ... ) in context of the component B, a new component A is presented inside component B.
As consequence, all components appear nested one inside the other. How to solve the issue?
You have to take in account the right context in which you perform the SwitchToDialog() operation. If you want to switch from dialog A to dialog B, then you have to perform SwitchToDialog( B, ... ) in context of the component, the dialog A belongs to. The simplest approach to achieve this is the usage of the Owner variable:
if ( IsCurrentDialog())
Owner.SwitchToDialog( new Unit::DialogB, ... );
Please note the usage of IsCurrentDialog() to avoid race conditions.
Does it help you further?
Best regards
Paul Banach