Donate

CheckBoxList Control With Multi-Highlighting Support In C# Windows Forms

If you want to customize the CheckBoxList control to support multi-highlighting (each checked item is highlighted), you can simply override the OnDrawItem() by adding Graphics statements as shown below:
Here's an image sample of the extended CheckBoxList control:
CheckBoxList Control With Multi-Highlighting Support In C# Windows Forms
Code:
protected override void OnDrawItem(DrawItemEventArgs e)  
     {  
       int index = e.Index;  
                if (this.GetItemCheckState(index) == CheckState.Checked)  
                {  
                     string text = this.Items[index].ToString();  
                     Graphics g = e.Graphics;  
                     Point point = this.GetItemRectangle(index).Location;  
                     point.X += estimated_point; //estimated point is a value you may set manually  
                     //background:  
                     SolidBrush backgroundBrush;            
                     backgroundBrush = reportsBackgroundBrushSelected;  
                     //estimated point is a value you may set manually  
                     g.FillRectangle(backgroundBrush, estimated_point , e.Bounds.Y, this.Width, e.Bounds.Height);  
                     //text:  
                     SolidBrush foregroundBrush = reportsForegroundBrushSelected;  
                     g.DrawString(text, e.Font, foregroundBrush, point);  
                }        
     }  

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations