<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AB-WebLog.com&#187; Visual Studio</title>
	<atom:link href="http://www.ab-weblog.com/en/tag/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ab-weblog.com/en</link>
	<description>Andreas Breitschopp</description>
	<lastBuildDate>Wed, 18 Mar 2015 09:47:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using Visual Studio Form Designer With Forms Extending Abstract Classes</title>
		<link>http://www.ab-weblog.com/en/using-visual-studio-form-designer-with-forms-extending-abstract-classes/</link>
		<comments>http://www.ab-weblog.com/en/using-visual-studio-form-designer-with-forms-extending-abstract-classes/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 13:31:18 +0000</pubDate>
		<dc:creator>Andreas Breitschopp</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[form designer]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ab-weblog.com/en/?p=315</guid>
		<description><![CDATA[For a recent project I wanted to create an abstract form base class. This way some global functionality can be inherited by all of my forms and interface methods can be defined. But the result was this error message as &#8230; <a href="http://www.ab-weblog.com/en/using-visual-studio-form-designer-with-forms-extending-abstract-classes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a recent project I wanted to create an abstract form base class. This way some global functionality can be inherited by all of my forms and interface methods can be defined.</p>
<p>But the result was this error message as soon as I tried to open one of my derived from classes in the Visual Studio form designer:</p>
<pre class="brush: text; gutter: false">The designer must create an instance of type &lt;type name&gt;, but it can't because the type is declared as abstract.</pre>
<p>Hereupon I&#8217;ve searched for a solution in the web and it seems that I was not the only one that had the idea to derive some form classes from an abstract base class. To solve the problem I&#8217;ve created a dummy implementation of my abstract base class and derived the form classes from this dummy implementation. This way the form classes can be displayed in the Visual Studio form designer again.</p>
<p>In C# the classes look like this then:</p>
<pre class="brush: csharp; gutter: true">public abstract partial class BaseForm : Form
{
  // Methods of your abstract class...
}

#if DEBUG
public class BaseFormImpl : BaseForm
{
  // The dummy implementation of the abstract BaseForm class.
}
#endif

#if DEBUG
public partial class RealForm : BaseFormImpl
#else
public partial class RealForm : BaseForm
#endif
{
  // One of the forms extending the base form.
}</pre>
<p>And for VB .NET developers it looks like this:</p>
<pre class="brush: vbnet; gutter: true">Public MustInherit Partial Class BaseForm
  Inherits Form
  ' Methods of the abstract base class...
End Class

#if DEBUG
Public Class BaseFormImpl
  Inherits BaseForm
  ' The dummy implementation of the abstract BaseForm class.
End Class
#endif

Public Partial Class RealForm
#if DEBUG
  Inherits BaseFormImpl
#else
  Inherits BaseForm
#endif
  ' One of the forms extending the base form.
End Class</pre>
<p>Probably you have noticed the compiler directives: obviously that&#8217;s not necessary that the forms work correctly inside the form designer again. But I don&#8217;t like to have unnecessary code inside the released product (and the dummy implementation of the abstract <em>BaseForm</em> class is really useless). Therefore I used these conditional compiler directives to make sure that this dummy class is only used in debug mode.</p>
<p><em>Did you come across this issue yourself already, too?</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ab-weblog.com/en/using-visual-studio-form-designer-with-forms-extending-abstract-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->