protected override void OnDrawItem(DrawItemEventArgs e) { Rectangle rTab = this.GetTabRect(e.Index); Rectangle rClose = GetCloseBtnRect(rTab); Rectangle rText = new Rectangle(new Point(rTab.Left + 2, rTab.Top + 2), new Size(rTab.Width - 13 - 6, rTab.Height - 4)); if (e.Graphics.ClipBounds.Contains(rClose)) { IntPtr pHdc = e.Graphics.GetHdc(); Point p = PointToClient(Control.MousePosition); if (e.Index == MouseDownIndex) { if (rClose.Contains(p)) { m_ThemeManager.DrawThemeBackground( UxThemeElements.WINDOW, pHdc, (int)WindowParts.SmallCloseButton, (int)CloseButtonState.Hot, ref rClose, IntPtr.Zero); } else { m_ThemeManager.DrawThemeBackground( UxThemeElements.WINDOW, pHdc, (int)WindowParts.SmallCloseButton, (int)CloseButtonState.Pressed, ref rClose, IntPtr.Zero); } } else { if (rClose.Contains(p)) { m_ThemeManager.DrawThemeBackground( UxThemeElements.WINDOW, pHdc, (int)WindowParts.SmallCloseButton, (int)CloseButtonState.Hot, ref rClose, IntPtr.Zero); } else { m_ThemeManager.DrawThemeBackground( UxThemeElements.WINDOW, pHdc, (int)WindowParts.SmallCloseButton, (int)CloseButtonState.Normal, ref rClose, IntPtr.Zero); } } e.Graphics.ReleaseHdc(pHdc); } if (e.Graphics.ClipBounds.Contains(rText)) { StringFormat sf = new StringFormat(); sf.FormatFlags |= StringFormatFlags.NoWrap; sf.Trimming |= StringTrimming.EllipsisCharacter; e.Graphics.DrawString(TabPages[e.Index].Text, Font, new SolidBrush(DefaultForeColor), rText, sf); } #if DEBUG e.Graphics.FillRectangle(Brushes.Green, rClose); e.Graphics.FillRectangle(Brushes.Red, rText); #endif }
private void DrawThemedBar(Graphics g) { IntPtr hdc = g.GetHdc(); Rectangle clientRect = this.ClientRectangle; m_ThemeManager.DrawThemeBackground(UxThemeElements.PROGRESS, hdc, 1, 1, ref clientRect, ref clientRect); double dblPercent = (m_dblValue - m_dblMinimum) / (m_dblMaximum - m_dblMinimum); // Calculate how much has the Pbar to be filled for "x" % int width = (int)(dblPercent * (this.Width - 2)); Rectangle chunkRect = new Rectangle(1, 1, width, this.ClientRectangle.Height - 2); m_ThemeManager.DrawThemeBackground(UxThemeElements.PROGRESS, hdc, 3, 1, ref chunkRect, ref chunkRect); g.ReleaseHdc(hdc); }
internal void DrawProgressBar(Graphics GFX, Rectangle drawRect) { if (drawRect.Width <= 0) { return; } if (m_Value == null) { return; } Rectangle clipRect = Rectangle.Ceiling(GFX.ClipBounds); clipRect.Intersect(drawRect); if (clipRect.IsEmpty) { return; } RectangleF oldClip = GFX.ClipBounds; GFX.SetClip(clipRect); double dblPercent = (double)Convert.ToDouble(m_Value) / 100.0; Rectangle valRect = GetValueRect(GFX, drawRect); if (UxThemeManager.VisualStylesEnabled()) { int oldWidth = valRect.Width; IntPtr hdc = GFX.GetHdc(); UxThemeManager themeManager = m_ParentRow.Parent.Themes[m_ParentRow.Parent]; themeManager.DrawThemeBackground(UxThemeElements.PROGRESS, hdc, 1, 1, ref valRect, ref clipRect); valRect.Width = (int)(dblPercent * valRect.Width); themeManager.DrawThemeBackground(UxThemeElements.PROGRESS, hdc, 3, 1, ref valRect, ref clipRect); GFX.ReleaseHdc(hdc); #if DEBUG valRect.Width = oldWidth; Brush drawRectColor = new SolidBrush(Color.Green); GFX.FillRectangle(drawRectColor, valRect); drawRectColor.Dispose(); #endif } else { Brush bordercolor = new SolidBrush(Color.DarkGray); Brush backcolor = new SolidBrush(Color.LightGray); Brush b = new SolidBrush(Color.Green); LinearGradientBrush lb = new LinearGradientBrush(valRect, Color.FromArgb(225, Color.White), Color.FromArgb(75, Color.Transparent), LinearGradientMode.Vertical); GFX.FillRectangle(bordercolor, valRect); valRect.Inflate(-1, -1); GFX.FillRectangle(backcolor, valRect); int oldWidth = valRect.Width; valRect.Width = (int)(dblPercent * valRect.Width); GFX.FillRectangle(b, valRect); valRect.Width = oldWidth; GFX.FillRectangle(lb, valRect); #if DEBUG Brush drawRectColor = new SolidBrush(Color.Green); valRect.Inflate(1, 1); GFX.FillRectangle(drawRectColor, valRect); drawRectColor.Dispose(); #endif backcolor.Dispose(); bordercolor.Dispose(); b.Dispose(); lb.Dispose(); } GFX.SetClip(oldClip); }