diff --git a/WDAC-Policy-Wizard/app/src/CustomRuleConditionsPanel.Designer.cs b/WDAC-Policy-Wizard/app/src/CustomRuleConditionsPanel.Designer.cs index 9e3a9c2..47a0e1d 100644 --- a/WDAC-Policy-Wizard/app/src/CustomRuleConditionsPanel.Designer.cs +++ b/WDAC-Policy-Wizard/app/src/CustomRuleConditionsPanel.Designer.cs @@ -693,16 +693,19 @@ private void InitializeComponent() panel_Publisher_Scroll.Controls.Add(textBoxSlider_4); panel_Publisher_Scroll.Controls.Add(textBoxSlider_1); panel_Publisher_Scroll.Controls.Add(textBoxSlider_0); + panel_Publisher_Scroll.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; panel_Publisher_Scroll.Location = new System.Drawing.Point(4, 389); panel_Publisher_Scroll.Margin = new System.Windows.Forms.Padding(2); panel_Publisher_Scroll.Name = "panel_Publisher_Scroll"; panel_Publisher_Scroll.Size = new System.Drawing.Size(510, 309); panel_Publisher_Scroll.TabIndex = 103; panel_Publisher_Scroll.Visible = false; + panel_Publisher_Scroll.Resize += Panel_Publisher_Scroll_Resize; // // textBoxSlider_2 // textBoxSlider_2.BackColor = System.Drawing.SystemColors.Control; + textBoxSlider_2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; textBoxSlider_2.Enabled = false; textBoxSlider_2.Font = new System.Drawing.Font("Tahoma", 9F); textBoxSlider_2.Location = new System.Drawing.Point(139, 100); @@ -776,6 +779,7 @@ private void InitializeComponent() // textBoxEKU // textBoxEKU.BackColor = System.Drawing.SystemColors.Control; + textBoxEKU.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; textBoxEKU.Enabled = false; textBoxEKU.Font = new System.Drawing.Font("Tahoma", 9F); textBoxEKU.Location = new System.Drawing.Point(139, 239); @@ -825,6 +829,7 @@ private void InitializeComponent() // textBox_MaxVersion // textBox_MaxVersion.BackColor = System.Drawing.SystemColors.Control; + textBox_MaxVersion.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; textBox_MaxVersion.Enabled = false; textBox_MaxVersion.Font = new System.Drawing.Font("Tahoma", 9F); textBox_MaxVersion.ForeColor = System.Drawing.SystemColors.WindowText; @@ -841,6 +846,7 @@ private void InitializeComponent() // textBoxSlider_3 // textBoxSlider_3.BackColor = System.Drawing.SystemColors.Control; + textBoxSlider_3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; textBoxSlider_3.Enabled = false; textBoxSlider_3.Font = new System.Drawing.Font("Tahoma", 9F); textBoxSlider_3.Location = new System.Drawing.Point(139, 142); @@ -854,6 +860,7 @@ private void InitializeComponent() // textBoxSlider_4 // textBoxSlider_4.BackColor = System.Drawing.SystemColors.Control; + textBoxSlider_4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; textBoxSlider_4.Enabled = false; textBoxSlider_4.Font = new System.Drawing.Font("Tahoma", 9F); textBoxSlider_4.Location = new System.Drawing.Point(139, 184); @@ -867,6 +874,7 @@ private void InitializeComponent() // textBoxSlider_1 // textBoxSlider_1.BackColor = System.Drawing.SystemColors.Control; + textBoxSlider_1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; textBoxSlider_1.Enabled = false; textBoxSlider_1.Font = new System.Drawing.Font("Tahoma", 9F); textBoxSlider_1.Location = new System.Drawing.Point(139, 58); @@ -880,6 +888,7 @@ private void InitializeComponent() // textBoxSlider_0 // textBoxSlider_0.BackColor = System.Drawing.SystemColors.Control; + textBoxSlider_0.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; textBoxSlider_0.Enabled = false; textBoxSlider_0.Font = new System.Drawing.Font("Tahoma", 9F); textBoxSlider_0.Location = new System.Drawing.Point(139, 16); diff --git a/WDAC-Policy-Wizard/app/src/CustomRuleConditionsPanel.cs b/WDAC-Policy-Wizard/app/src/CustomRuleConditionsPanel.cs index 1d44c93..9403b25 100644 --- a/WDAC-Policy-Wizard/app/src/CustomRuleConditionsPanel.cs +++ b/WDAC-Policy-Wizard/app/src/CustomRuleConditionsPanel.cs @@ -36,6 +36,24 @@ public partial class CustomRuleConditionsPanel : Form private string PrevComText = String.Empty; private bool IgnoreInput = false; + // X-coordinate of the slider value boxes (textBoxSlider_*) for the different rule types. + // File Attribute labels (e.g. "Original filename:") are wider than the Publisher labels, + // so the value boxes need to be shifted right to avoid overlapping the labels. + private const int DefaultSliderBoxX = 139; + private const int FileAttributeSliderBoxX = 165; + + // Padding kept between the right edge of the value boxes and the panel edge so the + // boxes never run off the right side of the window. + private const int SliderBoxRightPadding = 14; + + // Upper bound on the value box width so the boxes don't become unreasonably long on + // very wide windows. + private const int SliderBoxMaxWidth = 700; + + // Tracks the current left edge of the value boxes so the layout can be recomputed when + // the panel (and therefore the window) is resized. + private int currentSliderBoxX = DefaultSliderBoxX; + private enum UIState { RuleConditions = 0, @@ -1066,6 +1084,50 @@ private void SetFileSignerInfo(string refPath) this.PolicyCustomRule.SupportedCrypto = true; } + /// + /// Moves the slider value boxes (textBoxSlider_*) to the supplied X-coordinate so that wider + /// labels (e.g. File Attribute "Original filename:") do not overlap the value boxes. The right + /// edge is kept fixed so the boxes remain within the panel. + /// + /// The new X-coordinate for the left edge of the value boxes. + private void OffsetSliderValueBoxes(int xLocation) + { + this.currentSliderBoxX = xLocation; + + TextBox[] fullWidthBoxes = { this.textBoxSlider_0, this.textBoxSlider_1, this.textBoxSlider_2, this.textBoxSlider_3 }; + + // Expand the boxes to fill the panel, leaving padding on the right so they never run + // off the edge of the window. Cap the width so the boxes don't get too long. + int availableWidth = this.panel_Publisher_Scroll.ClientSize.Width - xLocation - SliderBoxRightPadding; + int newWidth = Math.Min(availableWidth, SliderBoxMaxWidth); + if (newWidth < 100) + { + newWidth = 100; // sanity floor + } + + foreach (TextBox box in fullWidthBoxes) + { + box.Location = new Point(xLocation, box.Location.Y); + box.Size = new Size(newWidth, box.Size.Height); + } + + // textBoxEKU spans the full width like the attribute boxes + this.textBoxEKU.Location = new Point(xLocation, this.textBoxEKU.Location.Y); + this.textBoxEKU.Size = new Size(newWidth, this.textBoxEKU.Size.Height); + + // textBoxSlider_4 (version box) keeps its own width but follows the same left edge + this.textBoxSlider_4.Location = new Point(xLocation, this.textBoxSlider_4.Location.Y); + } + + /// + /// Recomputes the slider value box layout when the panel is resized so the boxes grow + /// and shrink with the window width. + /// + private void Panel_Publisher_Scroll_Resize(object sender, EventArgs e) + { + OffsetSliderValueBoxes(this.currentSliderBoxX); + } + /// /// Sets the default state of the textboxes and checkboxes based on the rule type /// @@ -1137,6 +1199,9 @@ private void SetDefaultUIState(PolicyCustomRules.RuleType ruleType) this.checkBoxAttribute3.Text = "File name:"; this.checkBoxAttribute4.Text = "Min. Version:"; + // Publisher labels are narrow; restore the value boxes to their default position + OffsetSliderValueBoxes(DefaultSliderBoxX); + // Version textbox should be set to normal size this.textBoxSlider_4.Size = this.textBoxSlider_3.Size; @@ -1218,6 +1283,10 @@ private void SetDefaultUIState(PolicyCustomRules.RuleType ruleType) this.checkBoxAttribute2.Text = "Product name:"; this.checkBoxAttribute3.Text = "Internal name:"; + // The File Attribute labels (e.g. "Original filename:") are wider than the + // Publisher labels, so shift the value boxes right to avoid overlapping the labels + OffsetSliderValueBoxes(FileAttributeSliderBoxX); + // Set checkbox states to all disabled -- allow user to select the ones desired this.checkBoxAttribute0.Checked = false; this.checkBoxAttribute1.Checked = false;