简体   繁体   English

C#Winforms如何在CheckedListBox中设置复选框填充?

[英]C# winforms how to set padding for checkboxes in checkedlistbox?

在此处输入图片说明

In the above diagram ,I want to set padding (to RIGHT) for the check boxes in checkedlistbox. 在上图中,我要为清单列表中的复选框设置填充(向右)。

You can do a simple workaround to get your desired result, since there is no built-in Functionality for that: 您可以通过一种简单的解决方法来获得所需的结果,因为没有内置的功能:

private void Form1_Load(object sender, EventArgs e)
{
    CheckedListBox chkList = new CheckedListBox();
    chkList.BorderStyle = BorderStyle.None;
    chkList.Margin = new Padding(20, 3, 3, 3);
    chkList.Items.AddRange(new object[] { "A", "B", "C", "D", "E", "F" });
    FlowLayoutPanel fPanel = new FlowLayoutPanel();
    fPanel.Height = this.Height;
    chkList.BackColor = fPanel.BackColor = Color.White;
    fPanel.Controls.Add(chkList);

    this.Controls.Add(fPanel);
}

Feel free to do the same approach using the designer. 随意使用设计器执行相同的方法。

The CheckedListBox does not provide that function (as far as I see). CheckedListBox不提供该功能(据我所知)。
The only quick solution that I could think of is to simply add 2-3 spaces before every item text. 我能想到的唯一快速解决方案是在每个项目文本之前简单地添加2-3个空格。 This is 'dirty' but it would work. 这是“肮脏的”,但可以使用。
Other than that, you could only use something different like a DataGridView . 除此之外,您只能使用不同的东西,例如DataGridView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM