LoginSignup
3
2

More than 3 years have passed since last update.

WinFormsで、Genericクラスを継承したFormのデザイナ表示がエラーとなる問題の解決策

Last updated at Posted at 2018-11-14

結論

少々無理やりですが、Genericのフォームと派生クラスのフォーム間に非Genericクラスのフォームを挟むことで解消されました。
簡単ですが備忘のために書き残します。
以下の記事を参考にさせていただきました。というかほとんどそのままです。
 ジェネリックパラメータを持つFormを継承したFormをデザイナで表示できない。

追記 2020-02-22

コメントいただきましたので訂正します。
本記事のやり方は Visual Studio 2017 にて確認したものです。
Visual Studio 2019 ではこれでもエラーになるとのことでした。

具体的に

エラーとなるパターン(GenericFormを直接継承)

GenericForm.cs
namespace Sample

public class GenericForm<T> : Form
{

}
InheritForm.cs
namespace Sample

public class InheritForm : GenericForm<string>
{

}

InheritFormのデザイナを開こうとすると例外が発生する。

エラーを解消したパターン

GenericForm.cs
namespace Sample

public class GenericForm<T> : Form
{

}
NotGenericForm.cs
namespace Sample

public class NotGenericForm : GenericForm<string> { }
InheritForm.cs
namespace Sample

public class InheritForm : NotGenericForm
{

}

InheritFormのデザイナを通常通り開くことができる。
NotGenericFormのデザイナ画面は開けませんが(Genericを直接継承しているため)、中間クラスだと割り切って実装を空にしておけばそんなもんなのかなーと思ってます。

3
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2