Quantcast
Viewing all articles
Browse latest Browse all 12583

Problem with ListView.OnDrawColumnHeader method

Hi, I have a couple of problems:

I am trying to custom draw the column headers in C# and I am getting nowhere.

Firstly:

Certain parts of it work but others do not. In the documentation here http://msdn.microsoft.com/en-us/library/system.windows.forms.drawlistviewcolumnheadereventargs.state(v=vs.80).aspx It says that the e.State uses Hot and Selected flags.

I have tried to draw it with these without much success. When no mouse is over the header, it draws it how it would look normally as it should.  It seems to draw the mouse pressed state when in the "Selected" condition.

I have set OwnerDraw to true in the constructor of my derived list view.

Secondly:

The trailing end of the images is being blurred to being transparent, why is this?

Here is my code:

        protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
        {
            //http://msdn.microsoft.com/en-us/library/system.windows.forms.drawlistviewcolumnheadereventargs.state(v=vs.80).aspx
            //Use this property to determine whether the mouse pointer is over the header or
            //whether the user has clicked the header.
            //The ListViewItemStates values for these states are Hot and Selected.

            Graphics g = e.Graphics;

            ListViewItemStates ColumnState = e.State;
            if ((ColumnState & ListViewItemStates.Hot) == ListViewItemStates.Hot)

            {
                ImageAttributes ia = new ImageAttributes();
                ia.SetColorKey(Color.Red, Color.Red);
                g.DrawImage(imgW_Header.Images[1], e.Bounds, 0, 0,
                    imgW_Header.Images[1].Width, imgW_Header.Images[1].Height,
                    GraphicsUnit.Pixel, ia);

            }
            else if ((ColumnState & ListViewItemStates.Selected) == ListViewItemStates.Selected)
            {
                g.DrawImage(imgW_Header.Images[2], e.Bounds);
            }
            else
            {
                //draw default state
                g.DrawImage(imgW_Header.Images[0], e.Bounds);
            }

            base.OnDrawColumnHeader(e);
            
        }





Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>