Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Hide new Form at start

Tags:

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
like image 478
User6996 Avatar asked Dec 14 '22 00:12

User6996


1 Answers

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);
}
like image 160
Hans Passant Avatar answered Dec 26 '22 12:12

Hans Passant