简体   繁体   中英

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).
The only quick solution that I could think of is to simply add 2-3 spaces before every item text. This is 'dirty' but it would work.
Other than that, you could only use something different like a DataGridView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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