Border Color customization in ListBox and CheckedListBox
-
With BorderStyle set to Fixed Single, in the Paint method I tried to draw my own border color but the Paint would never get called for ListBox/CheckedListBox. Is there any difference from ListBox/CheckedListBox and other controls. I know that we need to override OnDrawItem , OnMeasureItem to customize the items in the ListBox but how do I change the border color of the ListBox itself? protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.BorderStyle == BorderStyle.FixedSingle) System.Windows.Forms.ControlPaint.DrawBorder(e.Graphics, ClientRectangle, _borderColor, ButtonBorderStyle.Solid); } Thanks in advance, VPMahank
-
With BorderStyle set to Fixed Single, in the Paint method I tried to draw my own border color but the Paint would never get called for ListBox/CheckedListBox. Is there any difference from ListBox/CheckedListBox and other controls. I know that we need to override OnDrawItem , OnMeasureItem to customize the items in the ListBox but how do I change the border color of the ListBox itself? protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.BorderStyle == BorderStyle.FixedSingle) System.Windows.Forms.ControlPaint.DrawBorder(e.Graphics, ClientRectangle, _borderColor, ButtonBorderStyle.Solid); } Thanks in advance, VPMahank
You may have to handle WM_NCPAINT to do this since the border is not part of the client area. Deus caritas est