Passing variables from the main form to the input form

I have a simple question. I have a main form and then a launch form, from where I can select a new 3D model to generate. When choosing a new three-dimensional model from the launch form, I want to first check whether the previous model I worked with is saved or not. I just want to pass a boolean value from the main form to the launch form using a delegate, but I can’t access the main form or any of its variables. I thought it would be as simple as saying: <code> frmMain myForm = new frmMain (); </code>, but frmMain input does not display anything in intellisense.

Any clues?

0
source share
3 answers

Add a public property in your main form

public bool IsDirty
{
    get;set;
}

you can access this.ParentForm.IsDirtyin your boot form,

don't forget to pass the link to the main form when showing the launch form ... startupForm.showDialog(this);

+3
source

Your main form is not available for the launch form. You must keep it in what is available at the point where you want to use it.

You can do it as follows (along with other ways :)

// This class is mainly used to transfer values in between different components of the system
    public class CCurrent
    {

        public static Boolean Saved = false;


    }

make sure you put this class in the namespace available for both forms.

Now in your frmMain form set the value CCurrent.Saved and get access to it in your start form.

0
source

: 3DModel :

private Model _model;

(, OpenFileDialog) - :

public void OpenModel()
{
    using(var frm=new StartUpForm())
    {
        if(frm.ShowDialog()==DialogResult.OK))
        {
            if(_model.IsDirty)
            {
                if(MessageBox.Show("Model is changed do you want to save it?","",MessageBoxButtons.YesNo)==DialogResult.Yes)
                    _model.Save();

                _model=frm.SelectedModel;
            }
        }
    }
}

your launch form should have this interface:

public interface IStartupForm:IDisposable
{
    DialogResult ShowDialog(IWin32Window parent);
    Model SelectedModel{get;}
}
0
source

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


All Articles