【问题标题】:CheckedListBox docking not working properlyCheckedListBox 对接无法正常工作
【发布时间】:2012-01-06 02:52:00
【问题描述】:

我为 Windows 窗体应用程序创建了一个用户控件。它只有一个带有四个单元格的 TableLayoutPanel。 Cell[0,0] 和 cell[0,1] 有标签。 Cell[1,0] 有一个树形视图,而 cell[1,1] 有 CheckedListBox。

对于所有四个控件,我已将停靠设置为填充。那个该死的 CheckedListBox 看起来比 TreeView 小。有什么方法可以让控件正确对接?

顺便说一句,我使用的是 .Net 3.5 和 VS 2010。

以下是控件的设计器文件代码:

namespace UserControls
{
    partial class LinkedContent
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.lblContentGroups = new System.Windows.Forms.Label();
            this.lblModules = new System.Windows.Forms.Label();
            this.tvContent = new System.Windows.Forms.TreeView();
            this.chkListBoxModules = new System.Windows.Forms.CheckedListBox();
            this.tableLayoutPanel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // tableLayoutPanel1
            // 
            this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
            this.tableLayoutPanel1.ColumnCount = 2;
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.Controls.Add(this.lblContentGroups, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.lblModules, 1, 0);
            this.tableLayoutPanel1.Controls.Add(this.tvContent, 0, 1);
            this.tableLayoutPanel1.Controls.Add(this.chkListBoxModules, 1, 1);
            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 2;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 7.760532F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 92.23947F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(501, 451);
            this.tableLayoutPanel1.TabIndex = 0;
            // 
            // lblContentGroups
            // 
            this.lblContentGroups.AutoSize = true;
            this.lblContentGroups.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lblContentGroups.Location = new System.Drawing.Point(4, 1);
            this.lblContentGroups.Name = "lblContentGroups";
            this.lblContentGroups.Size = new System.Drawing.Size(243, 34);
            this.lblContentGroups.TabIndex = 0;
            this.lblContentGroups.Text = "Content Groups";
            this.lblContentGroups.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // lblModules
            // 
            this.lblModules.AutoSize = true;
            this.lblModules.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lblModules.Location = new System.Drawing.Point(254, 1);
            this.lblModules.Name = "lblModules";
            this.lblModules.Size = new System.Drawing.Size(243, 34);
            this.lblModules.TabIndex = 1;
            this.lblModules.Text = "Modules";
            this.lblModules.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // tvContent
            // 
            this.tvContent.CheckBoxes = true;
            this.tvContent.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tvContent.Location = new System.Drawing.Point(4, 39);
            this.tvContent.Name = "tvContent";
            this.tvContent.Size = new System.Drawing.Size(243, 408);
            this.tvContent.TabIndex = 2;
            // 
            // chkListBoxModules
            // 
            this.chkListBoxModules.Dock = System.Windows.Forms.DockStyle.Fill;
            this.chkListBoxModules.FormattingEnabled = true;
            this.chkListBoxModules.Location = new System.Drawing.Point(254, 39);
            this.chkListBoxModules.Name = "chkListBoxModules";
            this.chkListBoxModules.Size = new System.Drawing.Size(243, 408);
            this.chkListBoxModules.TabIndex = 3;
            // 
            // LinkedContent
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.tableLayoutPanel1);
            this.Name = "LinkedContent";
            this.Size = new System.Drawing.Size(501, 451);
            this.tableLayoutPanel1.ResumeLayout(false);
            this.tableLayoutPanel1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
        private System.Windows.Forms.Label lblContentGroups;
        private System.Windows.Forms.Label lblModules;
        private System.Windows.Forms.TreeView tvContent;
        private System.Windows.Forms.CheckedListBox chkListBoxModules;
    }
}

【问题讨论】:

  • 你能放一张截图给我们看看它的样子吗?
  • 根据给定的信息,我无法重现所描述的行为。请为我们提供一些代码和屏幕截图 - thx

标签: c# winforms .net-3.5


【解决方案1】:

检查以确保未设置 IntegralHeight 属性。默认为真。

来自上面的 MSDN 链接:

当该属性设置为true时,控件自动调整大小 以确保项目没有部分显示。如果你想 根据空间保持ListBox的原始大小 根据您的表单要求,将此属性设置为 false。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-27
    • 2016-12-01
    • 2018-04-24
    • 2014-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多