vendredi 8 septembre 2023

How do I change the styles of checkboxes within a listview in winforms to be flatstyle = flat

My new winforms application is taking windows 11 styling. I want to set checkboxes back to how they looked on windows 10. But currently all i am able to do is add new checkboxes to the listview which sit ontop of the old ones. How do i update the existing checkbox style?

`

 foreach (ListViewItem item in listView.Items)
 {

     CheckBox checkBox = new CheckBox { };
     if (item.Checked)
     {
         // Create and add a new checkbox if it doesn't exist
         checkBox = new CheckBox
         {
             Name = item.Name,
             FlatStyle = FlatStyle.Flat,
             Checked = item.Checked,
             Bounds = new Rectangle(
                     listView.Items[item.Index].SubItems[0].Bounds.Left + 4,
                     item.Bounds.Top + 2, 18, 18)
         };


     }
     else
     {

         checkBox = new CheckBox
         {
             Name = item.Name,
             FlatStyle = FlatStyle.Flat,
             Checked = false,
             Bounds = new Rectangle(
                 listView.Items[item.Index].SubItems[0].Bounds.Left + 4,
                 item.Bounds.Top + 2, 18, 18)
         };


     }

     listView.Controls.Add(checkBox);

 }

`

I have tried creating new checkboxes and adding those controls to the listview.




Aucun commentaire:

Enregistrer un commentaire