2009-01-26 26 views
34

Visual Studio抱怨:警告1設計人員必須創建一個類型爲'RentalEase.CustomBindingNavForm'的實例,但它不能因爲該類型被聲明爲抽象。設計人員必須創建......的一個實例,因爲該類型被聲明爲抽象

Visual Studio不會讓我訪問窗體的Designer。該類已經實現了CustomBindingNavForm中的所有抽象方法。 CustomBindingNavForm提供了一些具體和抽象的函數。

有沒有辦法解決這個問題?

這裏是類:

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

的[我怎樣才能獲得Visual Studio 2008的Windows窗體設計來呈現,實現一個抽象基類的表單?(可能重複http://stackoverflow.com/questions/1620847/how-can -i-得到視覺工作室-2008-Windows的表單設計器渲染的-A型 - 即-IM) – 2015-09-02 08:44:42

回答

25

我還沒有看到在城市的馬鈴薯(其下),但我和Smelch內容與解決方案上來。 Form本身繼承自一個抽象類,所以他們不告訴你的是它的它的唯一的第一級繼承,不能抽象,第二個下來可以。

從那裏它簡單地在中間有一個空的類,圍繞形式聲明包裝#if debug,你很好去。只要確保在發佈模式和調試模式下進行設計(這是非常典型的)。

您將在設計(調試)和構建(發佈)時間獲得完整的設計器支持和真正的抽象基類,因爲每次它最終都會使用抽象基類。

The full explanation and answer is here

相關問題