call forms from a sql


I am doing a project in C # and I have a table in SQL that builds a dynamic tree menu and one of the fields has the name of the form that should be opened when clicking.

Now, in order not to make a fixed query and lose the dynamic effect of the menu setting, I want to use a call that can be unique and that gives it the name of the form I need and calls and urges it.

For example

In the menu, when I choose billing, call the form frmFacturacion

I should write

frmFacturacion fact = new frmFacturacion();

Now the frmFacturacion should be variable depending on each menu option you choose.

I hope you understand me and there is a possibility to do it.


asked by Pablo 21.07.2018 в 01:46

1 answer


If they are of the Form type you could use Activator.CreateInstance Knowing what the namespace is, replace the string with the "namespace" of the same or pass it by parameter if you wish (if you have different namespaces you store it in the db and do the same as the form).

  string strNombreForm = "frmFacturacion";
  var formObj = Activator.CreateInstance(Type.GetType("namespace." + formtocall)) as Form;
  formObj .ShowDialog();
answered by 21.07.2018 / 01:55