T
Tinus
Hello all,
[I've been programming in C# for several months now, so bare with me... I'm
still a newbie]
I've create a custom control (UserControl) and have a custom Item
Collection. The control is a custom calendar which is draw using the
Graphics Rectangle etc. functions. It is drawn when the control is painted
or resized. When the control is drawn it draws also the items found in the
collection.
So far so good.... I have 3 questions which I'm unable to find a solution
for yet (googled for several days now :-( ). Hopefull someone of you can
help me?
1. With a ListView control you can remove items using the
listView1.Items[1].Remove() or listView1.Remove(item). How does one
implement the first option (the second one I know how)?
2. The UserControl is drawn when the control is painted or resized (in the
event I call the function that draws the control). Every time I add a item
to the collection I have to call the control.Refresh() function to update my
control with the added item. How can I make it so that whenever I add an
item to my collection the control is (re)drawn automatically?
3. The drawn control flickers when I do a Refresh() or when I redraw the
control. I've already tried to remove the Graphics.Clear(Color) function but
that did not help :-( How can I reduce the flickering?
Below I placed the item collection code (simplified). Hopefully someone in
this newsgroup can tell me what to do with the first 2 questions.... they
are really bugging me.
Thanks in advance!
Regards,
Tinus
(The Netherlands)
----
public class Items : System.Collections.CollectionBase
{
public virtual Items Add(Item item)
{
if (this.List.Contains(item))
throw new InvalidOperationException();
this.List.Add(item);
return this;
}
public virtual Items Add(string name, int number)
{
return this.Add(new Data(name, number));
}
public virtual Item this[int index]
{
get
{
if (index < 0 || index > this.List.Count)
throw new ArgumentOutOfRangeException();
return (Item)this.List[index];
}
}
}
public class Item
{
private string name;
private int number;
public string Name
{
get
{
return this.name;
}
}
public int Number
{
get
{
return this.number;
}
set
{
if (value < 0)
throw new ArgumentOutOfRangeException();
this.number = value;
}
}
public Item(string name, int number)
{
this.name = name;
this.number = number;
}
}
[I've been programming in C# for several months now, so bare with me... I'm
still a newbie]
I've create a custom control (UserControl) and have a custom Item
Collection. The control is a custom calendar which is draw using the
Graphics Rectangle etc. functions. It is drawn when the control is painted
or resized. When the control is drawn it draws also the items found in the
collection.
So far so good.... I have 3 questions which I'm unable to find a solution
for yet (googled for several days now :-( ). Hopefull someone of you can
help me?
1. With a ListView control you can remove items using the
listView1.Items[1].Remove() or listView1.Remove(item). How does one
implement the first option (the second one I know how)?
2. The UserControl is drawn when the control is painted or resized (in the
event I call the function that draws the control). Every time I add a item
to the collection I have to call the control.Refresh() function to update my
control with the added item. How can I make it so that whenever I add an
item to my collection the control is (re)drawn automatically?
3. The drawn control flickers when I do a Refresh() or when I redraw the
control. I've already tried to remove the Graphics.Clear(Color) function but
that did not help :-( How can I reduce the flickering?
Below I placed the item collection code (simplified). Hopefully someone in
this newsgroup can tell me what to do with the first 2 questions.... they
are really bugging me.
Thanks in advance!
Regards,
Tinus
(The Netherlands)
----
public class Items : System.Collections.CollectionBase
{
public virtual Items Add(Item item)
{
if (this.List.Contains(item))
throw new InvalidOperationException();
this.List.Add(item);
return this;
}
public virtual Items Add(string name, int number)
{
return this.Add(new Data(name, number));
}
public virtual Item this[int index]
{
get
{
if (index < 0 || index > this.List.Count)
throw new ArgumentOutOfRangeException();
return (Item)this.List[index];
}
}
}
public class Item
{
private string name;
private int number;
public string Name
{
get
{
return this.name;
}
}
public int Number
{
get
{
return this.number;
}
set
{
if (value < 0)
throw new ArgumentOutOfRangeException();
this.number = value;
}
}
public Item(string name, int number)
{
this.name = name;
this.number = number;
}
}