2009-01-26 21 views
34

Visual Studio se queja: Advertencia 1 El diseñador debe crear una instancia del tipo 'RentalEase.CustomBindingNavForm' pero no puede porque el tipo se ha declarado abstracto .El diseñador debe crear una instancia de ... no se puede porque el tipo se ha declarado abstracto

Visual Studio no me deja acceder al Diseñador para el formulario. La clase ya implementa todos los métodos abstractos del CustomBindingNavForm. CustomBindingNavForm proporciona algunas funciones concretas y abstractas.

¿Hay alguna forma de evitar esto?

Aquí es la clase:

public abstract class CustomBindingNavForm : SingleInstanceForm {  

     //Flags for managing BindingSource 
     protected bool isNew = false; 
     protected bool isUpdating = false; 

     /// <summary> 
     /// This is so that when a new item is added, it sets isNew and firstPass to true. The Position Changed Event will look for 
     /// firstPass and if it is true set it to false. Then on the next pass, it will see it's false and set isNew to false. 
     /// This is needed because the Position Changed Event will fire when a new item is added. 
     /// </summary> 
     protected bool firstPass = false; 


     protected abstract bool validateInput(); 
     protected abstract void saveToDatabase(); 


     //manipulating binding 
     protected abstract void bindingSourceCancelResetCurrent(); 
     protected abstract void bindingSourceRemoveCurrent(); 
     protected abstract void bindingSourceMoveFirst(); 
     protected abstract void bindingSourceMoveNext(); 
     protected abstract void bindingSourceMoveLast(); 
     protected abstract void bindingSourceMovePrevious(); 
     protected abstract void bindingSourceAddNew(); 

     public void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e) { 
      if (validateInput()) { 
       bindingSourceMovePrevious(); 
      } else { 
       DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); 
       if (cont == DialogResult.OK) { 
        if (isNew) { 
         bindingSourceRemoveCurrent(); 
         isNew = false; 
        } else { 
         bindingSourceCancelResetCurrent(); 
         bindingSourceMovePrevious(); 
        } 
       } 
      } 
     } 

     public void bindingNavigatorAddNewItem_Click(object sender, EventArgs e) { 
      if (validateInput()) { 
       saveToDatabase(); 
       bool temp = isUpdating; 
       isUpdating = true; 
       bindingSourceAddNew(); 
       isUpdating = temp; 

       isNew = true; 
       firstPass = true; 
      } else { 
       DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); 
       if (cont == DialogResult.OK) { 

        if (isNew) { 
         bindingSourceRemoveCurrent(); 
         isNew = false; 
        } else { 
         bindingSourceCancelResetCurrent(); 
        } 

        bool temp = isUpdating; 
        isUpdating = true; 
        bindingSourceAddNew(); 
        isUpdating = temp; 

        isNew = true; 
        firstPass = true; 
       } 
      } 
     } 

     public void bindingNavigatorMoveFirstItem_Click(object sender, EventArgs e) { 
      if (validateInput()) { 
       bindingSourceMoveFirst(); 
      } else { 
       DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); 
       if (cont == DialogResult.OK) { 
        if (isNew) { 
         bindingSourceRemoveCurrent(); 
         isNew = false; 
        } else { 
         bindingSourceCancelResetCurrent(); 
        } 
        bindingSourceMoveFirst(); 
       } 
      } 
     } 

     public void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e) { 
      if (validateInput()) { 
       bindingSourceMoveNext(); 
      } else { 
       DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); 
       if (cont == DialogResult.OK) { 
        if (isNew) { 
         bindingSourceRemoveCurrent(); 
         isNew = false; 
        } else { 
         bindingSourceCancelResetCurrent(); 
        } 
        bindingSourceMoveNext(); 
       } 
      } 
     } 
    } 
+0

posible duplicado de [¿Cómo puedo obtener Visual Studio 2008 de Windows diseñador de formularios para hacer un formulario que implementa una clase base abstracta?] (Http://stackoverflow.com/questions/1620847/how-can -i-get-visual-studio-2008-windows-forms-designer-to-render-a-form-that-im) –

Respuesta

25

No he visto el contenido en patatas en urbana (su abajo), pero yo y Smelch se le ocurrió una solución. Form hereda de una clase abstracta, por lo que lo que no le dicen es que es solo el 1er nivel de herencia que no puede ser abstracto, el 2do encendido puede hacerlo.

A partir de ahí es simplemente una cuestión de tener una clase vacía en el medio y envolver un #if debug alrededor de la declaración de formularios y listo. Solo asegúrese de liberar en modo de lanzamiento y diseño en modo de depuración (que es muy típico).

Obtendrás la compatibilidad total con el diseñador y una clase base abstracta real en el momento del diseño (depuración) y compilación (versión) porque cada vez que termina usa tu clase base abstracta.

The full explanation and answer is here

Cuestiones relacionadas