Recently I was working on .NET Framework 4.8 and decided to change it to .NET 6
At .NET Framework 4.8 I was using the code below to draw a rectangle around the Listbox and to make the event DrawItem:
using (Pen penBorder = new Pen(Color.FromArgb(66, 66, 66), 2))
{
penBorder.Alignment = PenAlignment.Inset;
graph.DrawRectangle(penBorder, ModifiersLB.Location.X - 2, ModifiersLB.Location.Y - 2, ModifiersLB.Width + 4F, ModifiersLB.Height + 4F);
}
private void LB_DrawItem(DrawItemEventArgs e, ListBox LB)
{
Color backgroundColor = Color.FromArgb(50, 50, 50);
Color horizontalColor = Color.FromArgb(100, 100, 100);
if (e.Index >= 0)
{
SolidBrush sb = new SolidBrush(((e.State & DrawItemState.Selected) == DrawItemState.Selected) ? horizontalColor : backgroundColor);
e.Graphics.FillRectangle(sb, e.Bounds);
string text = LB.Items[e.Index].ToString();
SolidBrush tb = new SolidBrush(e.ForeColor);
e.Graphics.DrawString(text, e.Font, tb, LB.GetItemRectangle(e.Index).Location);
}
}
The problem is this code is only supported by Windows.
I decided to make this question because I was receiving a warning. I never really intended to make my app supported on all platforms. I just wanted to ask if there is a better way to do what I was doing so that I don't get the warning.
Is there a better method to do this code or is there a ListBox replacement that I could use?