コード例 #1
0
        protected List<Control> GenerateProperties(IConfiguration configuration)
        {
            if (configuration == null) { return null; }

            List<Control> listControls = new List<Control>();

            System.Windows.Forms.Label label;
            System.Windows.Forms.Label comment;
            System.Windows.Forms.Control control;

            IConfigurationItem[] items = configuration.ExportAsArray();

            int margin = 20;
            int widthUser = splitContainer.Panel2.Width - (2 * margin);
            int widthLabel = (widthUser - margin) / 2;
            int widthControl = (widthUser - margin) / 2;
            int height = 20;
            int row = 10;
            int skip = 10;

            label = new System.Windows.Forms.Label();
            label.Visible = false;
            label.Location = new System.Drawing.Point(margin, row);
            label.Size = new System.Drawing.Size(widthUser, height);
            label.TextAlign = ContentAlignment.MiddleCenter;
            //label.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
            label.Text = configuration.ID;
            label.Font = new Font(label.Font, FontStyle.Bold);
            row = row + height + skip;
            splitContainer.Panel2.Controls.Add(label);
            listControls.Add(label);

            foreach (IConfigurationItem item in items)
            {
                label = new System.Windows.Forms.Label();
                label.Tag = item;
                label.Visible = false;
                label.Location = new System.Drawing.Point(margin, row);
                label.Size = new System.Drawing.Size(widthLabel, height);
                label.TextAlign = ContentAlignment.MiddleLeft;
                //label.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                label.Text = item.ID + "";

                control = QIT.Common.Configurations.UserInterfaceMapperFactory.mapConfigurationItemIntoControl(item);
                if (control != null)
                {
                    control.Tag = item;
                    control.Visible = false;
                    control.Location = new System.Drawing.Point(margin + widthLabel + margin, row);
                    control.Size = new System.Drawing.Size(widthControl, height);
                    //control.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                }

                if (item.Comment != "")
                {
                    row = row + height + (skip / 2);
                    comment = new System.Windows.Forms.Label();
                    comment.Visible = false;
                    comment.Location = new System.Drawing.Point(margin, row);
                    comment.Size = new System.Drawing.Size(widthUser, height);
                    comment.TextAlign = ContentAlignment.MiddleRight;
                    //label.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                    comment.Text = item.Comment;
                }
                else
                {
                    comment = null;
                }

                row = row + height + skip;

                listControls.Add(label);
                splitContainer.Panel2.Controls.Add(label);
                if (control != null)
                {
                    listControls.Add(control);
                    splitContainer.Panel2.Controls.Add(control);
                }
                if (comment != null)
                {
                    listControls.Add(comment);
                    splitContainer.Panel2.Controls.Add(comment);
                }
            }

            return listControls;
        }