Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I'm trying to use the ownerDraw property and it seems to work at runtime but not drawn in vs2019 ?
Any idea why it works at runtime but drawing normal (without OwnerDraw in IDE ?)
Currently I only try with Header so the rest is not done and not drawn
public class UIListView : ListView
{
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
{
base.OnDrawColumnHeader(e);
using (SolidBrush backBrush = new SolidBrush(Color.DarkCyan))
{
e.Graphics.FillRectangle(backBrush, e.Bounds);
}
using (SolidBrush foreBrush = new SolidBrush(Color.DarkSalmon))
{
using (StringFormat sf = new StringFormat())
{
sf.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.FitBlackBox;
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(e.Header.Text, new Font(new FontFamily("Segoe UI"), (float)8.25, FontStyle.Regular), new SolidBrush(e.ForeColor), new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), sf);
}
//e.Graphics.DrawString(e.Header.Text, e.Font, foreBrush, e.Bounds);
}
}
protected override void OnDrawItem(DrawListViewItemEventArgs e)
{
base.OnDrawItem(e);
}
protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
{
base.OnDrawSubItem(e);
}
public void OnDrawnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
}
public UIListView()
{
this.OwnerDraw = true;
}
}
Hi, that's by design.
It's well described here: why-does-ondrawitem-event-for-a-listview-not-affect-the-design-time-environment
I tested your control with the designer attribute applied and it works fine.
[Designer(typeof(ControlDesigner))]
public class UIListView : ListView