![](https://static.goldenline.pl/user_photo_basic.jpg)
konto usunięte
Temat: UserControl
Witam,Mam takie pytanko odnośnie tworzenia kontrolek w C#. Mam property w swojej kontrolce. Property jest kolekcją klasy gdzie zaimplementowane jest jedno pole typu string. Chciałbym aby po dodaniu usunięciu "itema" z kolekcji moja kontrolka zrobiła repaint w desingerze. Ponieważ tyle ile itemów w kolekcji chciałbym mieć tyle groupboxów na swojej kontrolce. Poniżej trochę kodu. Z góry dziękuję za pomoc!
Klasa item'a
public class GroupClass
{
private string pGrpupName;
public string GroupName
{
get { return pGrpupName; }
set { pGrpupName = value; }
}
}
Kontrolka:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Design;
using System.Windows.Forms;
namespace WindowsFormsControlLibrary1
{
[Designer("System.Windows.Forms.Design.ParentControlDesigner", "IDesigner")]
public partial class UserControl1 : UserControl
{
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
private List<GroupClass> pGroups = new List<GroupClass>();
public UserControl1()
{
InitializeComponent();
}
[Category("test")]
[Description("test")]
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
public List<GroupClass> Groups
{
get { return pGroups; }
set {
pGroups = value;
ShowGroups();
this.Refresh();
}
}
public void ShowGroups()
{
if (pGroups != null)
{
for (int i = 0; i <= pGroups.Count - 1; i++)
{
GroupBox gb = new GroupBox();
gb.Text = pGroups[i].GroupName;
gb.Name = i.ToString();
gb.Parent = this;
gb.Show();
this.Controls.Add(gb);
gb.Dock = DockStyle.Top;
}
}
}
}
}