jeudi 30 novembre 2017

How to call a form constructor with reflection

_myCrudName is the name of the form I would like to open. below code works just fine how ever what I would like to do here is pass my DbContext to the MyCrud's Constructor. how do I do that? any help is appreciated

            var type = Type.GetType(_myCrudName);
            var MyForm = Activator.CreateInstance(type) as MyCrud;
            if (MyForm == null) return;

            using (MyForm)
            {
                MyForm.MyPrimaryKey = _myPrimaryKey;
                MyForm.MyPkValue = MyPkValue;

                MyForm.ShowDialog();
            }





Aucun commentaire:

Enregistrer un commentaire