2009-01-26 32 views
34

Visual Studio than phiền: Cảnh báo 1 Nhà thiết kế phải tạo một thể loại kiểu 'RentalEase.CustomBindingNavForm' nhưng không thể vì loại được khai báo là trừu tượng .Nhà thiết kế phải tạo một thể hiện ... không thể vì loại được khai báo trừu tượng

Visual Studio sẽ không cho phép tôi truy cập Trình thiết kế cho biểu mẫu. Lớp đã triển khai tất cả các phương thức trừu tượng từ CustomBindingNavForm. CustomBindingNavForm cung cấp một số chức năng cụ thể và trừu tượng.

Có cách nào khác không?

Đây là lớp:

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

thể trùng lặp của [Làm thế nào tôi có thể nhận được Visual Studio 2008 của Windows được thiết kế riêng hình thức để làm cho một mẫu mà thực hiện một lớp cơ sở trừu tượng?] (Http://stackoverflow.com/questions/1620847/how-can -i-get-visual-studio-2008-windows-forms-designer-to-render-a-form-that-im) –

Trả lời

25

Tôi đã không nhìn thấy nội dung ở khoai tây đô thị (xuống của nó) nhưng nhớ và Smelch đã đưa ra một giải pháp. Form chính nó kế thừa từ một lớp trừu tượng, vì vậy những gì họ không nói với bạn là của nó chỉ cấp 1 của thừa kế không thể trừu tượng, thứ 2 trên xuống có thể.

Từ đó chỉ đơn giản là vấn đề có một lớp trống ở giữa và gói #if debug xung quanh tờ khai biểu mẫu và bạn tốt để đi. Chỉ cần chắc chắn để phát hành trong chế độ phát hành và thiết kế trong chế độ gỡ lỗi (đó là rất điển hình).

Bạn sẽ nhận được hỗ trợ thiết kế đầy đủ và lớp cơ sở trừu tượng thực sự khi thiết kế (gỡ lỗi) và xây dựng (phát hành) bởi vì mỗi khi nó kết thúc bằng lớp cơ sở trừu tượng của bạn.

The full explanation and answer is here

Các vấn đề liên quan