Ich habe eigentlich den Code vor den Messages gemeint. Da ich mich mit Komponentenentwicklung unter .NET bis jetzt noch gar nicht beschäftigt habe, habe ich selbst mal etwas herumprobiert. Was soll ich sagen, es läuft
.
Code:
namespace ButtonPanel
{
/// <summary>
/// Eine vertikale Liste von Buttons, die das ClientRect des Panels voll
/// ausfüllen
/// </summary>
public class ButtonPanel : System.Windows.Forms.Panel
{
List<Button> buttonList = new List<Button>();
int buttonCount = 0;
const int ButtonHeight = 20;
[Browsable(false)]
public List<Button> ButtonList {
get {
return buttonList;
}
}
[DefaultValue(0)]
public int ButtonCount {
get {
return buttonCount;
}
set {
buttonCount = value;
int count = ButtonList.Count;
if (value < count) {
ButtonList.RemoveRange(value, count - value);
}
else {
for (int i = count; i < value; i++) {
Button button = new Button();
button.Parent = this;
button.Top = i * ButtonHeight;
button.Width = this.ClientSize.Width;
button.Height = ButtonHeight;
ButtonList.Add(button);
}
}
}
}
public ButtonPanel()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
protected override void OnResize(EventArgs e)
{
foreach (Button button in ButtonList) {
button.Width = this.ClientSize.Width;
}
base.OnResize(e);
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
//
// UserControl1
//
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(292, 266);
}
#endregion
}
}