Make sure action edit combo box for enums is long enough.
authorStephaneLenclud
Wed, 27 Jul 2016 17:09:10 +0200
changeset 224471cb4c8a09a
parent 223 f6272f65d8fc
child 225 6ccaa430aa23
Make sure action edit combo box for enums is long enough.
Server/FormEditAction.Designer.cs
Server/FormEditAction.cs
     1.1 --- a/Server/FormEditAction.Designer.cs	Wed Jul 27 15:05:58 2016 +0200
     1.2 +++ b/Server/FormEditAction.Designer.cs	Wed Jul 27 17:09:10 2016 +0200
     1.3 @@ -39,11 +39,13 @@
     1.4              // 
     1.5              // comboBoxActionType
     1.6              // 
     1.7 +            this.comboBoxActionType.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     1.8 +            | System.Windows.Forms.AnchorStyles.Right)));
     1.9              this.comboBoxActionType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    1.10              this.comboBoxActionType.FormattingEnabled = true;
    1.11              this.comboBoxActionType.Location = new System.Drawing.Point(55, 12);
    1.12              this.comboBoxActionType.Name = "comboBoxActionType";
    1.13 -            this.comboBoxActionType.Size = new System.Drawing.Size(333, 21);
    1.14 +            this.comboBoxActionType.Size = new System.Drawing.Size(272, 21);
    1.15              this.comboBoxActionType.Sorted = true;
    1.16              this.comboBoxActionType.TabIndex = 18;
    1.17              this.comboBoxActionType.SelectedIndexChanged += new System.EventHandler(this.comboBoxActionType_SelectedIndexChanged);
    1.18 @@ -86,6 +88,7 @@
    1.19              | System.Windows.Forms.AnchorStyles.Left) 
    1.20              | System.Windows.Forms.AnchorStyles.Right)));
    1.21              this.iTableLayoutPanel.AutoSize = true;
    1.22 +            this.iTableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    1.23              this.iTableLayoutPanel.ColumnCount = 2;
    1.24              this.iTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    1.25              this.iTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    1.26 @@ -94,7 +97,7 @@
    1.27              this.iTableLayoutPanel.RowCount = 2;
    1.28              this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    1.29              this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    1.30 -            this.iTableLayoutPanel.Size = new System.Drawing.Size(375, 16);
    1.31 +            this.iTableLayoutPanel.Size = new System.Drawing.Size(312, 16);
    1.32              this.iTableLayoutPanel.TabIndex = 23;
    1.33              // 
    1.34              // FormEditAction
    1.35 @@ -103,8 +106,9 @@
    1.36              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    1.37              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    1.38              this.AutoSize = true;
    1.39 +            this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    1.40              this.CancelButton = this.buttonCancel;
    1.41 -            this.ClientSize = new System.Drawing.Size(402, 107);
    1.42 +            this.ClientSize = new System.Drawing.Size(339, 107);
    1.43              this.Controls.Add(this.iTableLayoutPanel);
    1.44              this.Controls.Add(this.buttonCancel);
    1.45              this.Controls.Add(this.buttonOk);
     2.1 --- a/Server/FormEditAction.cs	Wed Jul 27 15:05:58 2016 +0200
     2.2 +++ b/Server/FormEditAction.cs	Wed Jul 27 17:09:10 2016 +0200
     2.3 @@ -136,18 +136,27 @@
     2.4              {
     2.5                  //Enum properties are using combo box
     2.6                  ComboBox ctrl = new ComboBox();
     2.7 -                ctrl.AutoSize = true;
     2.8 -                ctrl.Sorted = true;
     2.9 +                ctrl.AutoSize = true;                
    2.10 +                ctrl.Sorted = true;                
    2.11                  ctrl.DropDownStyle = ComboBoxStyle.DropDownList;
    2.12                  //Data source is fine but it gives us duplicate entries for duplicated enum values
    2.13                  //ctrl.DataSource = Enum.GetValues(aInfo.PropertyType);
    2.14  
    2.15                  //Therefore we need to explicitly create our items
    2.16 +                Size cbSize = new Size(0,0);
    2.17                  foreach (string name in aInfo.PropertyType.GetEnumNames())
    2.18                  {
    2.19                      ctrl.Items.Add(name.ToString());
    2.20 +                    Graphics g = this.CreateGraphics();
    2.21 +                    //Since combobox autosize would not work we need to get measure text ourselves
    2.22 +                    SizeF size=g.MeasureString(name.ToString(), ctrl.Font);
    2.23 +                    cbSize.Width = Math.Max(cbSize.Width,(int)size.Width);
    2.24 +                    cbSize.Height = Math.Max(cbSize.Height, (int)size.Height);
    2.25                  }
    2.26  
    2.27 +                //Make sure our combobox is large enough
    2.28 +                ctrl.MinimumSize = cbSize;
    2.29 +
    2.30                  // Instantiate our enum
    2.31                  object enumValue = Activator.CreateInstance(aInfo.PropertyType);
    2.32                  enumValue = aInfo.GetValue(aAction);
    2.33 @@ -246,6 +255,9 @@
    2.34                  iTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
    2.35                  //Create the label
    2.36                  Label label = new Label();
    2.37 +                label.AutoSize = true;
    2.38 +                label.Dock = DockStyle.Fill;
    2.39 +                label.TextAlign = ContentAlignment.MiddleCenter;
    2.40                  label.Text = attribute.Name;
    2.41                  toolTip.SetToolTip(label, attribute.Description);
    2.42                  iTableLayoutPanel.Controls.Add(label, 0, iTableLayoutPanel.RowCount-1);