Drawing large checkboxes for treeview

狂风中的少年 提交于 2019-12-12 05:01:41

问题


I am trying to make my treeview's checkboxes bigger. According to MSDN it says by default state images are capped at 16x16 and in order to use larger state images I need to specify this entry in the app.config file:

<appSettings>
  <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>

I tried adding this to my app.config and it did not change a thing, problem is the framework seems to actually shrink the images when I use 32x32 checkboxes.

Here is how I draw and set the checkboxes in my treeview's constructor:

public class MultiStateTreeView : TreeView
{
    public MultiStateTreeView() : base()
    {
        ImageList ilStateImages = new ImageList();
        ilStateImages.ImageSize = new Size(32, 32);
        for (int i = 0; i <= 4; i++)
        {                                               
             Bitmap bmpCheckBox = new Bitmap(32, 32);
             Graphics gfxCheckBox = Graphics.FromImage(bmpCheckBox);                            
             switch (i)
             {                                              
                 case 0: cbsState = CheckBoxState.UncheckedNormal; break;
                 case 1: cbsState = CheckBoxState.CheckedNormal; break;
                 case 2: cbsState = CheckBoxState.MixedNormal; break;
                 case 3: cbsState = CheckBoxState.UncheckedDisabled; break;
                 case 4: cbsState = CheckBoxState.UncheckedDisabled; break;
             }
             CheckBoxRenderer.DrawCheckBox(gfxCheckBox, new Point(2, 2), cbsState); 
             gfxCheckBox.Save();
             ilStateImages.Images.Add(bmpCheckBox);                                 
        }

        base.CheckBoxes = true;
        this.StateImageList = ilStateImages;
    }
}

Is there something that I am missing?

来源:https://stackoverflow.com/questions/37291184/drawing-large-checkboxes-for-treeview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!