Skip to content

Commit bc42ab3

Browse files
committed
Apply Theme to DataGridView cells
BreakPointUI grid was still rendering cells with the default background color. These changes update the DefaultCellStyle when themes are applied.
1 parent 36f0e2e commit bc42ab3

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎PluginCore/PluginCore/Controls/Common.cs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,30 @@ public override Size GetPreferredSize(Size constrainingSize)
154154

155155
}
156156

157-
public class DataGridViewEx : DataGridView
157+
public class DataGridViewEx : DataGridView, IEventHandler
158158
{
159159
public DataGridViewEx()
160160
{
161161
this.CellPainting += this.OnDataGridViewCellPainting;
162+
EventManager.AddEventHandler(this, EventType.ApplyTheme);
163+
}
164+
165+
public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority)
166+
{
167+
if (e.Type == EventType.ApplyTheme)
168+
{
169+
RefreshColors();
170+
}
171+
}
172+
173+
private void RefreshColors()
174+
{
175+
Color fore = PluginBase.MainForm.GetThemeColor("DataGridView.ForeColor");
176+
Color back = PluginBase.MainForm.GetThemeColor("DataGridView.BackColor");
177+
Color border = PluginBase.MainForm.GetThemeColor("ColumnHeader.BorderColor");
178+
DefaultCellStyle.ForeColor = (fore != Color.Empty) ? fore : SystemColors.WindowText;
179+
DefaultCellStyle.BackColor = (back != Color.Empty) ? back : SystemColors.Window;
180+
GridColor = (border != Color.Empty) ? border : SystemColors.ControlDark;
162181
}
163182

164183
private void OnDataGridViewCellPainting(Object sender, DataGridViewCellPaintingEventArgs e)

0 commit comments

Comments
 (0)