Hi,
I need to develop a custom control. The control is going to be something
like Properties window in VS - listview (grid?) with resizable columns and
collapsable sections.
The control needs to be read-only, so I do not need embeded text/listboxes,
but I need pictures and some more features. So I started to extend ListView
control. First I tried to do custom item selection (pseudo-code):
ListView:
protected override void WndProc(ref System.Windows. Forms.Message m) {
base.WndProc(re f m);
if (m.Msg == WindowMessages. PAINT)
for(int i = 0; i < this.items.Coun t; i++)
if (this.items[i].Selected)
(this.items[i]).DrawSelected( );
}
ListViewItem:
public void DrawSelected() {
Rectangle itemRect = GetBounds(ItemB oundsPortion.It emOnly);
Graphics g = Graphics.FromHw nd(base.ListVie w.Handle);
g.DrawRectangle (new Pen(Color.Red), itemRect);
g.FillRectangle (new SolidBrush(Colo r.Silver),
itemRect.X + 1, itemRect.Y + 1, itemRect.Width - 2,
itemRect.Height - 2);
g.DrawString(th is.Text, this.Font, new SolidBrush(Colo r.Black),
itemRect);
g.Dispose();
}
However, this work is 'try and guess' - strange effects appear like:
- moved text (probably it should be painted one pixel right, but why?)
- unselected items (painted by base.WndProc) have some unerased silver
background (probably FillRectangle is too large)
and so on
So the questions are:
- which Message(s) should I implement?
- how to use Rectangle(s)?
- which items should be painted? all, visible (how to check?)
- what about partially-hidden items?
- where to write texts?
- should I use base.WndProc; where?
- what is 'Erase Background' message? what is a [whatever] message?
- what about efficiency of WndProc? seems it should be fast
- and much more
I found: http://www.codeproject.com/cs/miscctrl/ . But it is not a good
point to start as some examples are complicated and poor documented. I need
a good article and in-depth explanation to start with. Just can't find one.
Regards.