Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在.NET中向CheckedListBox添加边距?_.net_Winforms_Checkedlistbox_Margins_Insets - Fatal编程技术网

如何在.NET中向CheckedListBox添加边距?

如何在.NET中向CheckedListBox添加边距?,.net,winforms,checkedlistbox,margins,insets,.net,Winforms,Checkedlistbox,Margins,Insets,我正在使用.NET IronPython编写一个windforms应用程序,但这并不相关,我的GUI中有一个CheckedListBox对象 它的工作很好,它有大约20个项目在一个多栏布局。但是我不知道如何给这个东西一个好的内部边距——我想在复选框的上、下、左、右边缘插入大约20或30像素的空白 为了清楚起见,我希望空白显示在CheckedListBox的边框和其内部的复选框之间,而不是整个组件的外部 希望这是一个简单的答案,我只是错过了它,因为我是在windows编程新手。如果不可能的话,我想

我正在使用.NET IronPython编写一个windforms应用程序,但这并不相关,我的GUI中有一个CheckedListBox对象

它的工作很好,它有大约20个项目在一个多栏布局。但是我不知道如何给这个东西一个好的内部边距——我想在复选框的上、下、左、右边缘插入大约20或30像素的空白

为了清楚起见,我希望空白显示在CheckedListBox的边框和其内部的复选框之间,而不是整个组件的外部

希望这是一个简单的答案,我只是错过了它,因为我是在windows编程新手。如果不可能的话,我想知道也很好,这样我就不会再浪费时间了


如果我在Swing Java中这样做,我会在我的组件上设置inset,或者可能构建一个包含一些空白的复合边框。

本机窗口控件不支持Padding属性,否则无法说服它。不是真正的问题。只需将BorderStyle设置为“无”,并将其放在AutoScroll属性为True的面板中。您必须在表单的加载事件中设置列表框大小,因为它可能会被重新缩放。哎呀,看起来不对。哦,好吧。

对于任何希望在复选框周围添加空间的人来说,最简单的方法是使用DataGridView并使其看起来像CheckedListBox。以下是我的一些设计器代码:

        // 
        // dgv1
        // 
        this.dgv1.AllowUserToAddRows = false;
        this.dgv1.AllowUserToDeleteRows = false;
        this.dgv1.AllowUserToResizeColumns = false;
        this.dgv1.AllowUserToResizeRows = false;
        this.dgv1.BackgroundColor = System.Drawing.SystemColors.Control;
        this.dgv1.BorderStyle = System.Windows.Forms.BorderStyle.None;
        this.dgv1.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None;
        this.dgv1.ColumnHeadersVisible = false;
        this.dgv1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
        this.dgvcChecked,
        this.dgvcValue});
        dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
        dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
        dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.ControlText;
        dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Control;
        dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.ControlText;
        dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
        this.dgv1.DefaultCellStyle = dataGridViewCellStyle3;
        this.dgv1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.dgv1.EnableHeadersVisualStyles = false;
        this.dgv1.Location = new System.Drawing.Point(7, 21);
        this.dgv1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
        this.dgv1.Name = "dgv1";
        this.dgv1.ReadOnly = true;
        this.dgv1.RowHeadersVisible = false;
        this.dgv1.RowTemplate.Height = 18;
        this.dgv1.RowTemplate.ReadOnly = true;
        this.dgv1.ShowCellErrors = false;
        this.dgv1.ShowCellToolTips = false;
        this.dgv1.ShowEditingIcon = false;
        this.dgv1.ShowRowErrors = false;
要获取或设置选中的项目,请执行以下操作:

    // gets or sets the checked items in dgv1 ( dgvcChecked.Index = 0, dgvcValue.Index = 1 )
    public string[] pSelected { 
        get {  return ( from DataGridViewRow r in dgv1.Rows 
                        where r.Cells[dgvcChecked.Index].Value.Equals(true) 
                        select r.Cells[dgvcValue.Index].Value as string ).ToArray(); 
        }
        set { 
            if (value != null && value.Length > 0)
                foreach (DataGridViewRow r in dgv1.Rows)
                    r.Cells[dgvcChecked.Index].Value = value.Contains(r.Cells[dgvcValue.Index].Value as string);
        }
    }

啊,我希望有一处房产或是我错过的东西。但很高兴知道,至少没有直接的方法可以做到这一点。谢谢