protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) { if (e != null) { ToolStripItem tsi = e.Item; // In high contrast mode, various colors of the default // color table are incorrect, thus check m_bCustomColorTable if ((tsi != null) && this.EnsureTextContrast && m_bCustomColorTable) { bool bDarkBack = this.IsDarkStyle; if (tsi.Selected || tsi.Pressed) { if ((tsi.Owner is ContextMenuStrip) || (tsi.OwnerItem != null)) { bDarkBack = UIUtil.IsDarkColor(this.ColorTable.MenuItemSelected); } else // Top menu item { if (tsi.Pressed) { bDarkBack = UIUtil.IsDarkColor( this.ColorTable.MenuItemPressedGradientMiddle); } else { bDarkBack = UIUtil.IsDarkColor(UIUtil.ColorMiddle( this.ColorTable.MenuItemSelectedGradientBegin, this.ColorTable.MenuItemSelectedGradientEnd)); } } } // e.TextColor might be incorrect, thus use tsi.ForeColor bool bDarkText = UIUtil.IsDarkColor(tsi.ForeColor); if (bDarkBack && bDarkText) { Debug.Assert(false); e.TextColor = Color.White; } else if (!bDarkBack && !bDarkText) { Debug.Assert(false); e.TextColor = Color.Black; } } } else { Debug.Assert(false); } base.OnRenderItemText(e); }
private void ColorSpecialColumns(ListView lv) { if (lv.Items.Count < 1) { return; } int colUsername = -1; int colPassword = -1; int colAATPassword = -1; foreach (ColumnHeader col in lv.Columns) { if (col.Text == KeePass.Resources.KPRes.UserName) { colUsername = col.Index; } if (col.Text == KeePass.Resources.KPRes.Password) { colPassword = col.Index; } if (col.Text == Config.PWColumnHeader) { colAATPassword = col.Index; } } if ((colPassword < 0) && (colAATPassword < 0)) { ColumnHeader h = new ColumnHeader(); h.Text = Config.PWColumnHeader; h.Name = Config.PWColumn; if (colUsername >= 0) { colAATPassword = colUsername + 1; if (colPassword >= colAATPassword) { colPassword++; } } else { colAATPassword = lv.Columns.Count; } lv.Columns.Insert(colAATPassword, h); for (int i = 0; i < lv.Items.Count; i++) { lv.Items[i].SubItems.Insert(colAATPassword, new ListViewItem.ListViewSubItem(lv.Items[i], KeePassLib.PwDefs.HiddenPassword)); } UIUtil.ResizeColumns(lv, true); } Color b = lv.Items[0].BackColor; Color f = lv.Items[0].ForeColor; if (KeePass.Program.Config.MainWindow.EntryListAlternatingBgColors) { b = UIUtil.GetAlternateColorEx(b); } else { b = UIUtil.ColorMiddle(b, UIUtil.ColorMiddle(b, f)); if (UIUtil.IsDarkColor(b)) { f = UIUtil.LightenColor(b, 1); } else { f = UIUtil.DarkenColor(b, 1); } } foreach (ListViewItem li in lv.Items) { li.UseItemStyleForSubItems = false; AdjustColors(li, colUsername, b, f); AdjustColors(li, colPassword, b, f); AdjustColors(li, colAATPassword, b, f); } }