public void Initialize(Z80NavBar.NavBarItem navItem, int width, Z80NavBar.Themes.ITheme theme, int depth) { _navItem = navItem; _theme = theme; _depth = depth; this.Height = navItem.Height; this.Width = width; this.BackColor = theme.BackgroundColor(depth); _initialized = true; }
protected override void OnPaint(PaintEventArgs e) { if (_initialized) { float yPos = this.Height / 2 - (_theme.FontItem(_depth).Height / 2); float xPos = 34; if (_navItem.ParentID != null) { xPos = (float)_navItem.LeftChild; } if (_navItem.Enabled) { if (_hover) { if (_navItem.Icon != null) { e.Graphics.DrawImage(_navItem.Icon.Hover, new PointF(8, 8)); } e.Graphics.DrawString(_navItem.Text, _theme.FontItem(_depth), _theme.BrushFontHover(_depth), new PointF(xPos, yPos)); //hover backcolor only in root nodes and items with 'childs' if ((_navItem.ParentID == null) || (_navItem.Childs != null && _navItem.Childs.Count > 0)) { this.BackColor = _theme.HoverBackgroundColor(_depth); // v glyph only in childs (not root nodes) if (_navItem.ParentID != null && _navItem.Childs != null) { Point p1 = new Point(this.Width - 4, this.Height / 2); Point p2 = new Point(this.Width - 12, this.Height / 2); Point p3 = new Point(this.Width - 8, ((this.Height / 2) + 4)); Point[] p = { p1, p2, p3 }; SolidBrush b = _theme.BrushFontHover(_depth); e.Graphics.FillPolygon(b, p); } } } else //not hover { if (!_navItem.Selected) { if (_navItem.Icon != null) { e.Graphics.DrawImage(_navItem.Icon.Default, new PointF(8, 8)); } e.Graphics.DrawString(_navItem.Text, _theme.FontItem(_depth), _theme.BrushFontItemNotSelected(_depth), new PointF(xPos, yPos)); this.BackColor = _theme.BackgroundColor(_depth); // v glyph only in childs (not root nodes) if (_navItem.ParentID != null && _navItem.Childs != null) { Point p1 = new Point(this.Width - 4, this.Height / 2); Point p2 = new Point(this.Width - 12, this.Height / 2); Point p3 = new Point(this.Width - 8, ((this.Height / 2) + 4)); Point[] p = { p1, p2, p3 }; SolidBrush b = _theme.BrushFontItemNotSelected(_depth); e.Graphics.FillPolygon(b, p); } } else //selected Item { if (_navItem.Icon != null) { e.Graphics.DrawImage(_navItem.Icon.Selected, new PointF(8, 8)); } e.Graphics.DrawString(_navItem.Text, _theme.FontItemSelected(_depth), _theme.BrushFontItemSelected(_depth), new PointF(xPos, yPos)); if ((_navItem.ParentID == null) || (_navItem.Childs != null && _navItem.Childs.Count > 0)) { this.BackColor = _theme.SelectedBackgroundColor(_depth); // < glyph: if (_navItem.Content) { Point p1 = new Point(this.Width - 8, this.Height / 2); Point p2 = new Point(this.Width, ((this.Height / 2) - 8)); Point p3 = new Point(this.Width, ((this.Height / 2) + 8)); Point[] p = { p1, p2, p3 }; SolidBrush b = new SolidBrush(_navItem.ContentBackColor); e.Graphics.FillPolygon(b, p); } } } } } else //Item disabled { this.Enabled = false; //if you want to display icon when item was unselected, uncomment this If sentence: //if (_navItem.Icon != null) // e.Graphics.DrawImage(_navItem.Icon.Selected, new PointF(8, 8)); e.Graphics.DrawString(_navItem.Text, _theme.FontItem(_depth), _theme.BrushFontItemDisable, new PointF(xPos, yPos)); this.BackColor = _theme.ItemDisableBackgroudColor; } } base.OnPaint(e); }