C# Hide new Form at start

c++winforms

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

Best Solution

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);
}
Related Question