コンポーネント選択時に表示されるプロパティウィンドウに独自のプロパティを追加する方法を紹介します。
コンポーネントのクラスにプロパティを追加します。
以下のコードを実装します。コンポーネントクラスのVisualComponentにMyKeyプロパティを追加します。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinformVisualComponent
{
public partial class VisualComponent : Control
{
private string pmyKey;
public string MyKey
{
set
{
pmyKey = value;
}
get
{
return pmyKey;
}
}
public VisualComponent()
{
InitializeComponent();
}
public VisualComponent(IContainer container)
{
container.Add(this);
InitializeComponent();
}
}
}
コンポーネントをビルドし、フォームデザイナに配置します。コンポーネントをクリックして選択しプロパティーウィンドウの表示内容を確認します。プロパティウィンドウのプロパティにコンポーネントクラスで実装したMyKeyプロパティが追加されています。