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;
}
}
}

}
}

konto usunięte

Temat: UserControl

`Piotr Sowa edytował(a) ten post dnia 12.02.12 o godzinie 15:33

konto usunięte

Temat: UserControl

W momencie dodawania/usuwania pozycji wywołaj

this.Invalidate();


Pozdrawiam
RadekRadosław Zajączkowski edytował(a) ten post dnia 12.10.09 o godzinie 08:36

konto usunięte

Temat: UserControl

Dzięki, Panowie

konto usunięte

Temat: UserControl

Prawie działa ;-)
Przy kliknięciu dodaj w edytorze kolekcji robi to co chciałem ale jeżeli kliknę przycisk usuń niestety nic się nie dzieje. Zrobiłem zdarzenie:

protected override void RemoveItem(int index)
{
EventHandler<ItemRemovedArgs<T>> beforehandler = BeforeItemRemoved;
EventHandler<ItemRemovedArgs<T>> afterhandler = AfterItemRemoved;
EventHandler handlerListChanged = ListChanged;
T item = default(T);
if (index >= 0)
item = this[index];
WRListClass<T> old = this;
if (beforehandler != null)
{
beforehandler(this, new ItemRemovedArgs<T>(index, item));
}
base.RemoveItem(index);
if (afterhandler != null)
{
afterhandler(this, new ItemRemovedArgs<T>(index, item));
}
if (handlerListChanged != null)
{
if (old != this)
handlerListChanged(this, null);
}
}

na podobnym (tylko na insert item) w debugowaniu kontrolki wchodzi do środka a przy tym nic się nie dzieje :(



Wyślij zaproszenie do