次のようなデザインタイム サポートを備えたカスタム ユーザー コントロールを作成しました。
プロジェクト/アセンブリ「MyUserControl」
- MyUserControl.cs
- MyUserControlDesigner.cs
コードは次のようになります。
namespace MyUserControl
{
[Designer("MyUserControl.Design.MyUserControlDesigner, MyUserControl", typeof(IDesigner))]
public class MyUserControl : Control
{
// Some stuff here
}
}
namespace MyUserControl.Design
{
public class MyUserControlDesigner : ControlDesigner
{
// Some other stuff here
}
}
これら 2 つのクラスが同じアセンブリにある限り、すべて正常に動作します。VS2012 には、すべてのデザイナー オプションが表示されます。しかし、明らかな理由 (System.Design などへの参照) から、デザイナー コードを MyUserControl アセンブリではなく、MyUserControl.Design に配置したいと考えています。だから私は同じソリューションで 2 番目のプロジェクトを作成します。
プロジェクト/アセンブリ「MyUserControl」
- MyUserControl.cs
プロジェクト/アセンブリ「MyUserControl.Design」
- MyUserControlDesigner.cs
コードは次のようになります。
namespace MyUserControl
{
[Designer("MyUserControl.Design.MyUserControlDesigner, MyUserControl.Design", typeof(IDesigner))]
public class MyUserControl : Control
{
// Some stuff here
}
}
これを使用すると、デザイナーがまったく見つかりません。VS2012 はインラインで選択可能なコンポーネントを表示しませんが、デザイナーがアタッチされていないコンポーネントのようです。
VS2012 がそれを見つけるためにデザイナー アセンブリを GAC に追加する必要がありますか、それともここで何が問題なのですか?
編集: MyUserControl.Design への参照を WindowsFormsApplication1 に追加すると、すべて正常に動作しますが、これはまさにあなたが望んでいないことです...