Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
OutputTB is a textbox
OutputRTB is a rich textbox

these 2 boxes are overlaped
and I swap them by show/hide and SendToBack/BringToFront
for my needs.

in not work I mean that if I restore the form window from minimized state
then all form controls repositions and overlaped each other.
and the user must to restart the app.

and work mean the form is restored to its ok state.


the relevent code is:

1. not work
C#
if(!IsAppRunning)
{
  if(FlipNextAllCKB.Checked == true)
  {
    OutputTB.Hide();
    OutputTB.SendToBack();
    OutputRTB.Show();
    OutputRTB.BringToFront();
    FlipNextAllCKB.Checked = true;
  }

  if(FlipNextAllCKB.Checked == false)
  {
    OutputRTB.Hide();
    OutputRTB.SendToBack();
    OutputTB.Show();
    OutputTB.BringToFront();
    FlipNextAllCKB.Checked = false;
  }
}


or
2. is work
C#
if(!IsAppRunning)
{
  if(FlipNextAllCKB.Checked == true)
  {
    OutputTB.Hide();
    if(this.WindowState == FormWindowState.Minimized) OutputTB.SendToBack();
    OutputRTB.Show();
    if(this.WindowState == FormWindowState.Minimized) OutputRTB.BringToFront();
    FlipNextAllCKB.Checked = true;
  }

  if(FlipNextAllCKB.Checked == false)
  {
    OutputRTB.Hide();
    if(this.WindowState == FormWindowState.Minimized) OutputRTB.SendToBack();
    OutputTB.Show();
    if(this.WindowState == FormWindowState.Minimized) OutputTB.BringToFront();
    FlipNextAllCKB.Checked = false;
  }
}


Thank you

What I have tried:

OutputTB is a textbox
OutputRTB is a rich textbox

these 2 boxes are overlaped
and I swap them by show/hide and SendToBack/BringToFront
for my needs.

in not work I mean that if I restore the form window from minimized state
then all form controls repositions and overlaped each other.
and the user must to restart the app.

and work mean the form is restored to its ok state.


the relevent code is:

1. not work
C#
if(!IsAppRunning)
{
  if(FlipNextAllCKB.Checked == true)
  {
    OutputTB.Hide();
    OutputTB.SendToBack();
    OutputRTB.Show();
    OutputRTB.BringToFront();
    FlipNextAllCKB.Checked = true;
  }

  if(FlipNextAllCKB.Checked == false)
  {
    OutputRTB.Hide();
    OutputRTB.SendToBack();
    OutputTB.Show();
    OutputTB.BringToFront();
    FlipNextAllCKB.Checked = false;
  }
}


or
2. is work
C#
if(!IsAppRunning)
{
  if(FlipNextAllCKB.Checked == true)
  {
    OutputTB.Hide();
    if(this.WindowState == FormWindowState.Minimized) OutputTB.SendToBack();
    OutputRTB.Show();
    if(this.WindowState == FormWindowState.Minimized) OutputRTB.BringToFront();
    FlipNextAllCKB.Checked = true;
  }

  if(FlipNextAllCKB.Checked == false)
  {
    OutputRTB.Hide();
    if(this.WindowState == FormWindowState.Minimized) OutputRTB.SendToBack();
    OutputTB.Show();
    if(this.WindowState == FormWindowState.Minimized) OutputTB.BringToFront();
    FlipNextAllCKB.Checked = false;
  }
}
Posted
Updated 31-May-22 6:57am
v2
Comments
Member 13569650 31-May-22 12:47pm    
I was expecting an explanation why this behave like that.

and I also will check if this will for my code

Thank you very much
0x01AA 31-May-22 12:55pm    
Hard to give you an explanation, because we do not know on which events the code you show will be triggered.

Basically set the property 'Visible' to either true or false should be enough. I really don't see a reason to use BringToFront/SendToBack. While writing... maybe this (BringToFront/SendToBack) is your problem because there is a chance it changes the visibility?
Member 13569650 31-May-22 15:05pm    
In fact I use control.show and control.hide.

accidentally I played with back/front
and I curious about that behaviour

the triggered event is a button click

anyway thank you very much
Member 15627495 1-Jun-22 3:54am    
I'm interested by the "why" ?
what are the expected goals with a kind of toggle between a textbox, and a rich textbox ??
keep just one of them : the rtb ( for rich contents ).

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