Skip to content

Commit

Permalink
fix the back color of edit textbox not updated from control appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
jingwood committed May 5, 2021
1 parent be5f6a7 commit 4fba21a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
5 changes: 1 addition & 4 deletions Editor/ControlAppearanceEditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,12 @@ private void colorPickerControl_ColorPicked(object sender, EventArgs e)
ControlAppearanceColors key = (ControlAppearanceColors)Enum.Parse(
typeof(ControlAppearanceColors), lstColors.SelectedItem.ToString());

grid.ControlStyle.SetColor(key, colorPickerControl.SolidColor);

grid.ControlStyle = grid.ControlStyle;
grid.ControlStyle[key] = colorPickerControl.SolidColor;
}

private void NumSelectionWidth_ValueChanged(object sender, EventArgs e)
{
grid.ControlStyle.SelectionBorderWidth = (float)numSelectionWidth.Value;
grid.Invalidate();
}
#endregion // Set Styles

Expand Down
34 changes: 26 additions & 8 deletions ReoGrid/Control/ControlShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void InitControl()
this.builtInCrossCursor = LoadCursorFromResource(unvell.ReoGrid.Properties.Resources.cross);
#endif // WINFORM || WPF

this.controlStyle = ControlAppearanceStyle.CreateDefaultControlStyle();
this.ControlStyle = ControlAppearanceStyle.CreateDefaultControlStyle();
}

private void InitWorkbook(IControlAdapter adapter)
Expand Down Expand Up @@ -1273,21 +1273,39 @@ public ControlAppearanceStyle ControlStyle
get { return this.controlStyle; }
set
{
this.controlStyle = value ?? throw new ArgumentNullException("ControlStyle", "cannot set ControlStyle to null");
if (value == null)
{
throw new ArgumentNullException("ControlStyle", "cannot set ControlStyle to null");
}

if (this.controlStyle != value)
{
if (this.controlStyle != null) this.controlStyle.CurrentControl = null;
this.controlStyle = value;
}
//workbook.SetControlStyle(value);

this.adapter.Invalidate();
this.ApplyControlStyle();
}
}

internal void ApplyControlStyle()
{
this.controlStyle.CurrentControl = this;

#if WINFORM
sheetTab.BackColor = value[ControlAppearanceColors.SheetTabBackground];
this.BackColor = value[ControlAppearanceColors.GridBackground];
sheetTab.BackColor = this.controlStyle[ControlAppearanceColors.SheetTabBackground];
this.BackColor = this.controlStyle[ControlAppearanceColors.GridBackground];
#elif WPF
sheetTab.Background = new System.Windows.Media.SolidColorBrush(value[ControlAppearanceColors.SheetTabBackground]);
sheetTab.Background = new System.Windows.Media.SolidColorBrush(this.controlStyle[ControlAppearanceColors.SheetTabBackground]);
#endif // WINFORM & WPF

}
this.adapter?.Invalidate();
}
#endregion // App

//private AppearanceStyle appearanceStyle = new AppearanceStyle(this);

#endregion // Appearance

#region Mouse
private void OnWorksheetMouseDown(RGPointF location, MouseButtons buttons)
Expand Down
8 changes: 7 additions & 1 deletion ReoGrid/Core/Workbook/Appearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public enum ControlAppearanceColors : short
/// </summary>
public class ControlAppearanceStyle
{
internal ReoGridControl CurrentControl { get; set; }

private Dictionary<ControlAppearanceColors, SolidColor> colors = new Dictionary<ControlAppearanceColors, SolidColor>(100);

internal Dictionary<ControlAppearanceColors, SolidColor> Colors
Expand Down Expand Up @@ -116,6 +118,7 @@ public bool GetColor(ControlAppearanceColors colorKey, out SolidColor color)
public void SetColor(ControlAppearanceColors colorKey, SolidColor color)
{
colors[colorKey] = color;
this.CurrentControl?.ApplyControlStyle();
}

/// <summary>
Expand All @@ -133,7 +136,10 @@ public SolidColor this[ControlAppearanceColors colorKey]
else
return SolidColor.Black;
}
set { SetColor(colorKey, value); }
set
{
SetColor(colorKey, value);
}
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion ReoGrid/WinForm/WinFormControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ public void ShowEditControl(Graphics.Rectangle bounds, Cell cell)
editTextbox.InitialSize = rect.Size;
editTextbox.VAlign = cell.InnerStyle.VAlign;
editTextbox.Font = cell.RenderFont;
editTextbox.ForeColor = cell.InnerStyle.TextColor;
editTextbox.ForeColor = cell.InnerStyle.HasStyle(PlainStyleFlag.TextColor)
? cell.InnerStyle.TextColor : this.control.ControlStyle[ControlAppearanceColors.GridText];
editTextbox.BackColor = cell.InnerStyle.HasStyle(PlainStyleFlag.BackColor)
? cell.InnerStyle.BackColor : this.control.ControlStyle[ControlAppearanceColors.GridBackground];
editTextbox.ResumeLayout();
Expand Down

0 comments on commit 4fba21a

Please sign in to comment.