2009-01-26 3 views
34

Visual Studio beschwert sich: Warnung 1 Der Designer muss eine Instanz des Typs 'RentalEase.CustomBindingNavForm' erstellen, aber nicht, da der Typ als abstrakt deklariert ist .Der Designer muss eine Instanz erstellen ... kann nicht, weil der Typ als abstrakt deklariert wird

Visual Studio lässt mich nicht auf den Designer für das Formular zugreifen. Die Klasse implementiert bereits alle abstrakten Methoden aus dem CustomBindingNavForm. CustomBindingNavForm stellt einige Funktionen konkret und abstrakt zur Verfügung.

Gibt es einen Weg um dies? Hier

ist die Klasse:

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

möglich Duplikat [Wie kann ich Visual Studio 2008 Windows Forms Designer erhalten Sie ein Formular zu machen, die eine abstrakte Basisklasse implementiert?] (Http://stackoverflow.com/questions/1620847/how-can -i-get-visual-studio-2008-windows-forms-designer-zu-render-a-form-das-im) –

Antwort

25

ich nicht auf den Inhalt an städtischer Kartoffel gesehen habe (sein nach unten), aber ich und Smelch kam mit einer Lösung auf. Form erbt selbst von einer abstrakten Klasse, so was sie dir nicht sagen, ist, dass es ist nur die erste Ebene der Vererbung, die nicht abstrakt sein kann, kann die zweite auf.

Von dort ist es einfach eine Frage von einer leeren Klasse in der Mitte und ein #if debug um die Forms Deklaration und Sie sind gut zu gehen. Stellen Sie sicher, dass Sie den Release-Modus freigeben und im Debug-Modus arbeiten (was sehr typisch ist).

Sie erhalten volle Designunterstützung und eine echte abstrakte Basisklasse beim Design (Debug) und Build (Release), da jedes Mal die abstrakte Basisklasse verwendet wird.

The full explanation and answer is here

Verwandte Themen