C # Hide new form at the beginning

I have a form that is hidden, and it loads the subform, and the 2e form should be hidden, and

Please note: I no longer use

ShowInTaskbar = false; //  should be hidden too

and most of all I can communicate between forms, if I use (hide / apparently), I can not communicate until its visible = true;

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

I 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
+3
source share
6 answers

I really don't understand why you could make it work in one and not in the other. Preventing form visibility when calling the Show () method requires overriding the SetVisibleCore method. Perhaps you can use 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);
}
+5
source

For future googlers / searchers ...

, , , (, ReportViever , ​​ ), , ...

, Opacity = 0 form_Load, . Windows Windows 2000 .

+3

, .

- , formobject.Visiable = false

Form m = new Form();
m.Visible = false;
+1

, frm2.Hide();

  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);
        }
    }
+1

An alternative version of the Hans Passant code is toggle the switch as soon as the initial hide occurs:

    private bool _hasHiddenInitially = false;

    protected override void SetVisibleCore(bool value)
    {
        if (value && !IsHandleCreated) CreateHandle(); // Ensure Load event runs
        if (!_hasHiddenInitially) value = false;
        base.SetVisibleCore(value);
        _hasHiddenInitially = true;
    }
+1
source
    public NewForm()
    {
        InitializeComponent();


        SetVisibleCore(false);


    }

    private bool setCore = false;

    protected override void SetVisibleCore(bool value)
    {
        base.SetVisibleCore(setCore ? value : setCore);
    }

Maybe this will help

0
source

Source: https://habr.com/ru/post/1726451/


All Articles