8000 BackColor and ForeColor in DrawListViewColumnHeaderEventArgs have alpha component set to 0 · Issue #13048 · dotnet/winforms · GitHub
[go: up one dir, main page]

Skip to content
BackColor and ForeColor in DrawListViewColumnHeaderEventArgs have alpha component set to 0 #13048
Closed
@anders9ustafsson

Description

@anders9ustafsson

.NET version

.NET 8.0

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No response

Issue description

In our code, we are using the OwnerDraw mode for System.Windows.Forms.ListView. When accessing the ForeColor and BackColor properties of DrawListViewColumnHeaderEventArgs, we notice that the alpha component of respective color is 0, although we would have expected 255. Therefore, e.g. when drawing text using ForeColor, no text can be seen in the header.

Looking at the source code where DrawListViewColumnHeaderEventArgs is defined in ListView, I notice that the colors are obtained using P/Invoke methods GetTextColor and GetBkColor, respectively:

Color foreColor = Color.FromArgb((int)PInvoke.GetTextColor(nmcd->hdc).Value);
Color backColor = Color.FromArgb((int)PInvoke.GetBkColor(nmcd->hdc).Value);

However, if I interpret the documentation for the GetTextColor function correctly, it returns a COLORREF value, which only appears to be an RGB color representation with remaining byte set to 0 (0x00bbggrr). Is this the explanation why the alpha component is 0 in the ForeColor and BackColor properties?

Steps to reproduce

var listView = new ListView { OwnerDraw = true, View = View.Details, Columns = { "A", "B", "C" } };
listView.DrawColumnHeader += (s, e) => e.Graphics.DrawString(e.Header.Text, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Location);

Compare with:

var listView = new ListView { OwnerDraw = false, View = View.Details, Columns = { "A", "B", "C" } };

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0