tags:

views:

239

answers:

4

hi,

Ihave a form which is hidden and this loads a subform the 2e form should be hidden aswell

Please notes: I most not use

ShowInTaskbar = false; //  should be hidden too

and I most be able to communicate between forms if I use (hide/visible) i cant communicate until its visible = true;

  this.SetParameterValueCallback += new SetParameterValueDelegate(ShowMain.SetParamValueCallbackFn);
        ShowMain.AddItemCallback = new AddItemDelegate(this.AddItemCallbackFn);
        //Showsub.Show();
        Showsub.Hide(); // not working

I have tried so far

this.Visible = false; // didnt work

 BeginInvoke(new MethodInvoker(delegate
            {
                Hide();
            })); // didnt work

base.SetVisibleCore(false); // didnt work, Im not able communicate between form
+1  A: 

May be I did not understand the problem

But if you have any form you can hide it using formobject.Visiable = false

Form m = new Form();
m.Visible = false;
Ahmed Said
not working I most be able to communicate between forms
Power-Mosfet
+1  A: 

this is how i do it on my form, if you use frm2.Hide(); it might do the trix

  private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            main_normal frm2 = new main_normal();
            this.Hide(); //Hides Form1

            frm2.ShowDialog(); //Displays main_normal

            this.ShowDialog(); //After the main_normal is closed, again displays Form1
        }
        catch (Exception ex)
        {
            //this.Show();
            MessageBox.Show(ex.Message, "wub wub Noe feilet men eg vet isje ka", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
Darkmage
Like @darkmage has done, you have to create a new instance of the second form within your main form before you can do anything with it. Then you just hide your main form and show the second one. You can also use the .Show() method if you don't want the form to show dialog style.
ryanulit
+2  A: 

I don't really understand why you would be able to make it work in one but not the other. Preventing a form from getting visible when its Show() method is called requires overriding the SetVisibleCore method. Perhaps you can leverage this code:

private bool mAllowVisible = false;

public bool ReallyVisible {
  get { return mAllowVisible; }
  set {
    mAllowVisible = value;
    if (value) this.Visible = true;
  }
}

protected override void SetVisibleCore(bool value) {
  if (value && !IsHandleCreated) CreateHandle();  // Ensure Load event runs
  if (!ReallyVisible) value = false;
  base.SetVisibleCore(value);
}
Hans Passant
thank you Hans.
Power-Mosfet
A: 

For future googlers/searchers...

Sometimes you want the form to be invisible, but for it to think that it's visible (for example, ReportViever control won't render anything, if the form will be set invisible by the method from chosen answer), or you want to display second form at the program start in another thread and don't want to annoy user by blinking the first forms title...

If so, you can just set the Opacity = 0 on the form_Load event and it'll do the thing. This magic Windows behavior is know from Windows 2000 and helps very much in some cases.

Gman