相关疑难解决方法(0)

设计者必须创建一个......的实例,因为该类型被声明为abstract

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 …
Run Code Online (Sandbox Code Playgroud)

.net c# abstract winforms

35
推荐指数
1
解决办法
2万
查看次数

Visual Studio设计器中的抽象UserControl继承

abstract class CustomControl : UserControl 
{
    protected abstract int DoStuff();
}

class DetailControl : CustomControl
{
    protected override int DoStuff()
    { 
        // do stuff
        return result;
    }
}
Run Code Online (Sandbox Code Playgroud)

我在表单中删除了一个DetailControl.它在运行时正确呈现,但设计器显示错误并且无法打开,因为基本用户控件是抽象的.

目前,我正在考虑以下补丁,这对我来说似乎很不对,因为我希望子类被强制实现该方法.

class CustomControl : UserControl 
{
    protected virtual int DoStuff()
    {
        throw new InvalidOperationException("This method must be overriden.");
    }
}

class DetailControl : CustomControl
{
    protected override int DoStuff()
    { 
        // do stuff
        return result;
    }
}
Run Code Online (Sandbox Code Playgroud)

任何人都有更好的想法如何解决这个问题?

c# user-controls abstract-class winforms

31
推荐指数
3
解决办法
2万
查看次数

从抽象类继承的Usercontrol

我有一个继承自抽象类的usercontrol.基本上看起来像这样.

class SimpleSlideView : View
{

}

public abstract class View : UserControl
{

}
Run Code Online (Sandbox Code Playgroud)

该项目编译并运行良好.我可以使用usercontrol(从工具箱中)并将其拖动到表单中,并在设计器中正确显示.但是,如果我尝试SimpleSlideView在设计器中打开控件本身,则会收到以下错误:

设计者必须创建一个类型为"Animation.View"的实例,但它不能,因为该类型被声明为abstract.

我错过了什么?

c# abstract-class designer windows-forms-designer

6
推荐指数
1
解决办法
9194
查看次数

在VS Designer上使用Form(Of T)

我正在使用vb.net(vs2010).我正在将一些winforms移动到dll.我有一个继承自具有一些子和函数的表单(如测试应用程序).

我的原始表格是:(.designer)

Partial Class Form1(Of T)
    Inherits System.Windows.Forms.Form 
....
End Class


Form itself contains code and a toolbar.
Run Code Online (Sandbox Code Playgroud)

我的测试表格是:(.designer)

Partial Class TestForm
    Inherits Form1(Of Class1)
Run Code Online (Sandbox Code Playgroud)

我得到"无法创建Form1`1 [T]的实例,因为当VS尝试加载设计器时,Type.ContainsGenericParameters为true".应用程序可用.我可以无错误地构建和运行项目,但我需要为每个新表单添加控件和一些代码.

我试过很多方法:

所有的例子都是针对C#的,我不知道我是否遗漏了一些东西......

这是一个糟糕的设计吗?我知道这是一个VS bug,但似乎每个人都通过这些链接修复它.

编辑:

我正在构建一个DLL.Form1在此DLL上,TestForm在新项目中.如果我在同一个项目(也就是dll)中,这些链接有效.

谢谢!

vb.net inheritance designer visual-studio-2010 winforms

5
推荐指数
1
解决办法
867
查看次数