これは私のカスタム コントロール クラスです。
// Extended ComboBox where ill change some property.
public class ExtComboBox : ComboBox
{
...
}
// ExtButton is a control that i am going to drop on Form from ToolBox.
public partial class ExtButton : Button
{
public ExtComboBox ComboBoxInsideButton { get; set; }
public ExtButton()
{
InitializeComponent();
ComboBoxInsideButton = new ExtComboBox();
ComboBoxInsideButton.Text = "hi!";
Controls.Add(ComboBoxInsideButton);
}
}
基本的に、このコントロールをフォームに追加すると、ボタンの上に ComboBox が表示されます。なぜこれが必要なのか聞かないでください:D
ComboBox テキストを変更する必要がある場合は、次を使用します。
extButton1.ComboBoxInsideButton.Text = "aaa";
すべて正常に動作します..しかし:)プロジェクトを再構築または実行した後、デザインモードでいくつかのComboBoxプロパティを変更しようとすると(ウィンドウプロパティ-> ComboBoxInsideButtonを展開->テキストを「bbb」に変更)、ComboBoxプロパティがリセットされます(ExtButton.Designer .cs)
質問 1: サブコントロールをいくつかのデフォルト プロパティ値で初期化する方法。フォームにコントロールをドロップすると、すべての設定が追加されますか?
と
質問 2: デザイン時にサブコントロールのプロパティを変更する方法。
編集:
ここで答えてください:デザイナーは、サブコントロールのプロパティのコードを生成しません。なんで?
追加[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
すると問題が解決します。