protected override void OnPaint(PaintEventArgs e) { if (m_bThemed && UxThemeManager.VisualStylesEnabled()) { DrawThemedBar(e.Graphics); } else { DrawNonThemedBar(e.Graphics); } base.OnPaint(e); }
internal void DrawCheckBox(Graphics GFX, Rectangle drawRect) { if (drawRect.Width <= 0) { return; } if (m_Value == null) { return; } Rectangle valRect = GetValueRect(GFX, drawRect); if (UxThemeManager.VisualStylesEnabled()) { Rectangle clipRect = Rectangle.Intersect(Rectangle.Round(GFX.ClipBounds), drawRect); IntPtr hdc = GFX.GetHdc(); m_ParentRow.Parent.Themes[m_ParentRow.Parent].DrawThemeBackground(UxThemeElements.BUTTON, hdc, (int)ButtonPart.Checkbox, (bool)m_Value ? (int)CheckBoxState.CheckedNormal : (int)CheckBoxState.UncheckedNormal, ref valRect, ref clipRect); GFX.ReleaseHdc(hdc); } else { // TODO: Do this with the Graphics object, not with an image Bitmap ChkBox; System.Reflection.Assembly thisExe; thisExe = System.Reflection.Assembly.GetExecutingAssembly(); if ((bool)m_Value) { ChkBox = new Bitmap(thisExe.GetManifestResourceStream("DataList2.Checked.bmp")); } else { ChkBox = new Bitmap(thisExe.GetManifestResourceStream("DataList2.Unchecked.bmp")); } GFX.DrawImage(ChkBox, new Point(drawRect.X + (Width - ChkBox.Width) / 2, drawRect.Y + (Height - ChkBox.Width) / 2)); } #if DEBUG Brush drawRectColor = new SolidBrush(Color.Green); GFX.FillRectangle(drawRectColor, valRect); drawRectColor.Dispose(); #endif }
void WmNcpaint(ref Message m) { if (!UxThemeManager.VisualStylesEnabled()) { return; } ///////////////////////////////////////////////////////////////////////////// // Get the DC of the window frame and paint the border using uxTheme API´s ///////////////////////////////////////////////////////////////////////////// // set the part id to TextBox int partId = (int)ComboBoxPart.Border; // define the windows frame rectangle of the TextBox RECT windowRect; Win32.GetWindowRect(this.Handle, out windowRect); windowRect.Right -= windowRect.Left; windowRect.Bottom -= windowRect.Top; windowRect.Top = windowRect.Left = 0; // get the device context of the window frame IntPtr hDC = Win32.GetWindowDC(this.Handle); // define a rectangle inside the borders and exclude it from the DC RECT clientRect = windowRect; clientRect.Left += this.borderRect.Left; clientRect.Top += this.borderRect.Top; clientRect.Right -= this.borderRect.Right; clientRect.Bottom -= this.borderRect.Bottom; Win32.ExcludeClipRect(hDC, clientRect.Left, clientRect.Top, clientRect.Right, clientRect.Bottom); // make sure the background is updated when transparent background is used. if (m_ThemeManager[this].IsThemeBackgroundPartiallyTransparent(UxThemeElements.COMBOBOX, partId, m_nStateId)) { m_ThemeManager[this].DrawThemeParentBackground(hDC, ref windowRect); } // draw background m_ThemeManager[this].DrawThemeBackground(UxThemeElements.COMBOBOX, hDC, partId, m_nStateId, ref windowRect, IntPtr.Zero); // release dc Win32.ReleaseDC(this.Handle, hDC); // we have processed the message so set the result to zero m.Result = IntPtr.Zero; base.WndProc(ref m); }
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); }
protected override void OnPaint(PaintEventArgs e) { try { if (m_bIsComboBox) { Row CurSel = m_RowWnd.CurrSel; bool bHaveRow = m_RowWnd.CurrSel != null; SolidBrush Backcolor; if (m_AllowRowColorCombo && bHaveRow) { Backcolor = new SolidBrush(m_RowWnd.GetRowColor(ColorSelection.BackColor, m_RowWnd.CurrSel)); } else { Backcolor = new SolidBrush(m_RowWnd.BackColor); } e.Graphics.FillRectangle(Backcolor, this.ClientRectangle); Backcolor.Dispose(); Rectangle BtnRect = GetButtonRect(); if (UxThemeManager.VisualStylesEnabled()) { IntPtr hDC = e.Graphics.GetHdc(); m_ThemeManager[this].DrawThemeBackground(UxThemeElements.COMBOBOX, hDC, (int)ComboBoxPart.DropDownButtonRight, GetComboButtonState(), ref BtnRect, IntPtr.Zero); e.Graphics.ReleaseHdc(hDC); } int nWidth = this.ClientRectangle.Width - BtnRect.Width - 2; if (nWidth > 0) { int nHeight = this.ClientRectangle.Height - 2; if (nHeight > 0) { bool bNeedSelColor = (IsDroppedDown || ContainsFocus) && !ReadOnly; if (bNeedSelColor) { SolidBrush SelBackcolor; if (m_AllowRowColorCombo && bHaveRow) { SelBackcolor = new SolidBrush(m_RowWnd.GetRowColor(ColorSelection.SelBackColor, CurSel)); } else { SelBackcolor = new SolidBrush(SystemColors.Highlight); } e.Graphics.FillRectangle(SelBackcolor, 1, 1, nWidth, nHeight); SelBackcolor.Dispose(); Pen p = new Pen(Color.DarkGray); p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; e.Graphics.DrawRectangle(p, 1, 1, nWidth, nHeight); p.Dispose(); } nWidth -= 4; nHeight -= 8; if (nWidth > 0 && nHeight > 0) { StringFormat sf = new StringFormat(); sf.FormatFlags = System.Drawing.StringFormatFlags.NoWrap; sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; Brush ForText; if (bHaveRow) { ForText = new SolidBrush(m_RowWnd.GetRowColor(bNeedSelColor ? ColorSelection.SelForeColor : ColorSelection.ForeColor, CurSel)); } else { ForText = new SolidBrush(bNeedSelColor ? SystemColors.HighlightText : this.ForeColor); } e.Graphics.DrawString(bHaveRow ? CurSel.ToString(m_strComboFormat) : m_strComboText, this.Font, ForText, new Rectangle(5, 5, nWidth, nHeight), sf); ForText.Dispose(); sf.Dispose(); } } } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } base.OnPaint(e); }
private void WmNccalcsize(ref Message m) { // we visual styles are not enabled and BorderStyle is not Fixed3D then we have nothing more to do. if (!UxThemeManager.VisualStylesEnabled()) { return; } // contains detailed information about WM_NCCALCSIZE message NCCALCSIZE_PARAMS par = new NCCALCSIZE_PARAMS(); // contains the window frame RECT RECT windowRect; if (m.WParam == IntPtr.Zero) // LParam points to a RECT struct { windowRect = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT)); } else // LParam points to a NCCALCSIZE_PARAMS struct { par = (NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NCCALCSIZE_PARAMS)); windowRect = par.rgrc0; } // contains the client area of the control RECT contentRect; // get the DC IntPtr hDC = Win32.GetWindowDC(this.Handle); // find out how much space the borders needs if (m_ThemeManager[this].GetThemeBackgroundContentRect(UxThemeElements.COMBOBOX, hDC, (int)ComboBoxPart.Border, (int)ComboBoxState.Normal, ref windowRect, out contentRect)) { // shrink the client area the make more space for containing text. contentRect.Inflate(-1, -1); // remember the space of the borders this.borderRect = new RECT(contentRect.Left - windowRect.Left , contentRect.Top - windowRect.Top , windowRect.Right - contentRect.Right , windowRect.Bottom - contentRect.Bottom); // update LParam of the message with the new client area if (m.WParam == IntPtr.Zero) { Marshal.StructureToPtr(contentRect, m.LParam, false); } else { par.rgrc0 = contentRect; Marshal.StructureToPtr(par, m.LParam, false); } // force the control to redraw it´s client area m.Result = new IntPtr(0x200 | 0x100); } // release DC Win32.ReleaseDC(this.Handle, hDC); base.WndProc(ref m); }