OwnerDraw Bug

Arsium ***** 331 Reputation points
2021-08-12T18:41:26.52+00:00

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;
        }
    }
Developer technologies | C#
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.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Adnan Dedic 406 Reputation points
    2021-08-12T19:16:48.37+00:00

    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   
    

    122881-listview-ownerdraw-capture.jpg


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.