@@ -205,44 +205,56 @@ static internal void PluginCleanUp()
205205 /// </summary>
206206 /// <param name="form">a Windows Form</param>
207207 /// <param name="isDark">is Notepad++ dark mode on?</param>
208- static internal void ToggleDarkMode ( Form form , bool isDark )
208+ static internal void ToggleDarkMode ( Control ctrl , bool isDark )
209209 {
210- if ( form == null )
210+ if ( ctrl == null )
211211 return ;
212212 IntPtr themePtr = notepad . GetDarkModeColors ( ) ;
213213 if ( isDark && themePtr == IntPtr . Zero )
214214 return ;
215215 var theme = ( DarkModeColors ) Marshal . PtrToStructure ( themePtr , typeof ( DarkModeColors ) ) ;
216- foreach ( Form childForm in form . OwnedForms )
216+ if ( ctrl is Form form )
217217 {
218- // allow possibility that some forms will have other child forms
219- // JsonTools does this in a couple of places
220- ToggleDarkMode ( childForm , isDark ) ;
218+ foreach ( Form childForm in form . OwnedForms )
219+ {
220+ // allow possibility that some forms will have other child forms
221+ // JsonTools does this in a couple of places
222+ ToggleDarkMode ( childForm , isDark ) ;
223+ }
221224 }
222225 if ( isDark )
223226 {
224- form . BackColor = NppDarkMode . BGRToColor ( theme . Background ) ;
225- form . ForeColor = NppDarkMode . BGRToColor ( theme . Text ) ;
227+ ctrl . BackColor = NppDarkMode . BGRToColor ( theme . Background ) ;
228+ ctrl . ForeColor = NppDarkMode . BGRToColor ( theme . Text ) ;
226229 }
227230 else
228231 {
229- form . ResetForeColor ( ) ;
230- form . ResetBackColor ( ) ;
232+ ctrl . ResetForeColor ( ) ;
233+ ctrl . ResetBackColor ( ) ;
231234 }
232- foreach ( Control ctrl in form . Controls )
235+ foreach ( Control child in ctrl . Controls )
233236 {
234237 if ( isDark )
235238 {
236239 // this doesn't actually make disabled controls have different colors
237240 // windows forms don't make it easy for the user to choose the
238241 // color of a disabled control. See https://stackoverflow.com/questions/136129/windows-forms-how-do-you-change-the-font-color-for-a-disabled-label
239- var textTheme = ctrl . Enabled ? theme . Text : theme . DisabledText ;
240- if ( ctrl is Button btn )
242+ var textTheme = child . Enabled ? theme . Text : theme . DisabledText ;
243+ Color foreColor = NppDarkMode . BGRToColor ( textTheme ) ;
244+ Color backColor = NppDarkMode . BGRToColor ( theme . PureBackground ) ;
245+ Color InBetween = Color . FromArgb (
246+ foreColor . R / 4 + 3 * backColor . R / 4 ,
247+ foreColor . G / 4 + 3 * backColor . G / 4 ,
248+ foreColor . B / 4 + 3 * backColor . B / 4
249+ ) ;
250+ if ( child is GroupBox )
251+ ToggleDarkMode ( child , isDark ) ;
252+ else if ( child is Button btn )
241253 {
242254 btn . BackColor = NppDarkMode . BGRToColor ( theme . SofterBackground ) ;
243- btn . ForeColor = NppDarkMode . BGRToColor ( textTheme ) ;
255+ btn . ForeColor = foreColor ;
244256 }
245- else if ( ctrl is LinkLabel llbl )
257+ else if ( child is LinkLabel llbl )
246258 {
247259 llbl . BackColor = NppDarkMode . BGRToColor ( theme . ErrorBackground ) ;
248260 llbl . ForeColor = NppDarkMode . BGRToColor ( theme . DarkerText ) ;
@@ -251,36 +263,60 @@ static internal void ToggleDarkMode(Form form, bool isDark)
251263 llbl . VisitedLinkColor = NppDarkMode . BGRToColor ( theme . DarkerText ) ;
252264 }
253265 // other common text-based controls
254- else if ( ctrl is TextBox
255- || ctrl is Label
256- || ctrl is ListBox
257- || ctrl is ComboBox )
266+ else if ( child is TextBox
267+ || child is Label
268+ || child is ListBox
269+ || child is ComboBox )
258270 {
259- ctrl . BackColor = NppDarkMode . BGRToColor ( theme . PureBackground ) ;
260- ctrl . ForeColor = NppDarkMode . BGRToColor ( textTheme ) ;
271+ child . BackColor = backColor ;
272+ child . ForeColor = foreColor ;
261273 }
262- else if ( ctrl is TreeView tv )
274+ else if ( child is TreeView tv )
263275 {
264276 tv . BackColor = NppDarkMode . BGRToColor ( theme . HotBackground ) ;
265- tv . ForeColor = NppDarkMode . BGRToColor ( textTheme ) ;
277+ tv . ForeColor = foreColor ;
278+ }
279+ else if ( child is DataGridView dgv )
280+ {
281+ dgv . EnableHeadersVisualStyles = false ;
282+ dgv . BackgroundColor = InBetween ;
283+ dgv . ForeColor = foreColor ;
284+ dgv . GridColor = foreColor ;
285+ dgv . ColumnHeadersDefaultCellStyle . ForeColor = foreColor ;
286+ dgv . ColumnHeadersDefaultCellStyle . BackColor = backColor ;
287+ dgv . RowHeadersDefaultCellStyle . ForeColor = foreColor ;
288+ dgv . RowHeadersDefaultCellStyle . BackColor = backColor ;
289+ dgv . RowsDefaultCellStyle . ForeColor = foreColor ;
290+ dgv . RowsDefaultCellStyle . BackColor = backColor ;
266291 }
267292 else
268293 {
269294 // other controls I haven't thought of yet
270- ctrl . BackColor = NppDarkMode . BGRToColor ( theme . SofterBackground ) ;
271- ctrl . ForeColor = NppDarkMode . BGRToColor ( textTheme ) ;
295+ child . BackColor = NppDarkMode . BGRToColor ( theme . SofterBackground ) ;
296+ child . ForeColor = foreColor ;
272297 }
273298 }
274299 else // normal light mode
275300 {
276- ctrl . ResetForeColor ( ) ;
277- ctrl . ResetBackColor ( ) ;
278- if ( ctrl is LinkLabel llbl )
301+ child . ResetForeColor ( ) ;
302+ child . ResetBackColor ( ) ;
303+ if ( child is GroupBox )
304+ ToggleDarkMode ( child , isDark ) ;
305+ if ( child is LinkLabel llbl )
279306 {
280307 llbl . LinkColor = Color . Blue ;
281308 llbl . ActiveLinkColor = Color . Red ;
282309 llbl . VisitedLinkColor = Color . Purple ;
283310 }
311+ else if ( child is DataGridView dgv )
312+ {
313+ dgv . EnableHeadersVisualStyles = true ;
314+ dgv . BackgroundColor = SystemColors . ControlDark ;
315+ dgv . ForeColor = SystemColors . ControlText ;
316+ dgv . GridColor = SystemColors . ControlLight ;
317+ dgv . RowsDefaultCellStyle . ForeColor = SystemColors . ControlText ;
318+ dgv . RowsDefaultCellStyle . BackColor = SystemColors . Window ;
319+ }
284320 }
285321 }
286322 Marshal . FreeHGlobal ( themePtr ) ;
0 commit comments