internal unsafe void DrawBackground(IDeviceContext dc, Rectangle bounds, Rectangle clipRectangle, IntPtr hWnd) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } if (bounds.Width < 0 || bounds.Height < 0) { return; } if (clipRectangle.Width < 0 || clipRectangle.Height < 0) { return; } using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, AllGraphicsProperties)) { HandleRef hdc = new HandleRef(wgr, wgr.WindowsGraphics.DeviceContext.Hdc); if (IntPtr.Zero != hWnd) { using (ThemeHandle hTheme = ThemeHandle.Create(_class, true, hWnd)) { RECT rect = bounds; RECT clipRect = clipRectangle; lastHResult = UxTheme.DrawThemeBackground(hTheme, hdc, part, state, ref rect, &clipRect); } } else { RECT rect = bounds; RECT clipRect = clipRectangle; lastHResult = UxTheme.DrawThemeBackground(this, hdc, part, state, ref rect, &clipRect); } } }
public override void DrawBackground(Graphics graphics, Rectangle bounds) { using (var mh = ManagedHdc.FromGraphics(graphics)) { var rect = Win32.RECT.FromRectangle(bounds); UxTheme.DrawThemeBackground(_theme, mh.Hdc, _partId, _stateId, ref rect, IntPtr.Zero); } }
private void DrawBorder(System.Drawing.Graphics g) { IntPtr hTheme = UxTheme.OpenThemeData(this.Handle, "EDIT"); // Makes sure Windows XP is running and // a .manifest file exists for the EXE. if (Environment.OSVersion.Version.Major >= 5 && Environment.OSVersion.Version.Minor > 0 && System.IO.File.Exists(Application.ExecutablePath + ".manifest") && (hTheme != IntPtr.Zero)) { //Get DC IntPtr hDC = g.GetHdc(); int state = (int)UxTheme.ETS_NORMAL; switch (this.m_state) { case State.Disabled: state = (int)UxTheme.ETS_DISABLED; break; default: break; } try { RECT r = new RECT(this.ClientRectangle.Left, this.ClientRectangle.Right, this.ClientRectangle.Top, this.ClientRectangle.Bottom); //Render button IntPtr hr = UxTheme.DrawThemeBackground(hTheme, hDC, UxTheme.EP_EDITTEXT, state, r, null); } finally { //Release DC g.ReleaseHdc(hDC); UxTheme.CloseThemeData(hTheme); } } else { using (Graphics y = this.CreateGraphics()) { ControlPaint.DrawBorder(y, ClientRectangle, SystemColors.Control, ButtonBorderStyle.Inset); } } }
private void OnBtnPaint(object sender, System.Windows.Forms.PaintEventArgs e) { IntPtr hTheme = UxTheme.OpenThemeData(this.Handle, "COMBOBOX"); // Makes sure Windows XP is running and // a .manifest file exists for the EXE. if (Environment.OSVersion.Version.Major >= 5 & Environment.OSVersion.Version.Minor > 0 & System.IO.File.Exists(Application.ExecutablePath + ".manifest") & (hTheme != IntPtr.Zero)) { //Grab DC IntPtr hDC = e.Graphics.GetHdc(); int state = UxTheme.CBXS_NORMAL; switch (this.m_state) { case State.Hot: state = UxTheme.CBXS_HOT; break; case State.Pressed: state = UxTheme.CBXS_PRESSED; break; case State.Disabled: state = UxTheme.CBXS_DISABLED; break; default: break; } try { RECT r = new RECT(e.ClipRectangle.Left, e.ClipRectangle.Right, e.ClipRectangle.Top, e.ClipRectangle.Bottom); //Render button UxTheme.DrawThemeBackground(hTheme, hDC, UxTheme.CP_DROPDOWN, state, r, null); } finally { //Release DC e.Graphics.ReleaseHdc(hDC); UxTheme.CloseThemeData(hTheme); } } else { ButtonState state = ButtonState.Normal; switch (this.m_state) { case State.Pressed: state = ButtonState.Pushed; break; case State.Disabled: state = ButtonState.Inactive; break; default: break; } ControlPaint.DrawComboButton(e.Graphics, e.ClipRectangle, state); } }
/// <summary> /// Processes Windows messages /// </summary> /// <param name="m">The Windows Message to process</param> protected override void WndProc(ref Message m) { base.WndProc(ref m); if (!this.visualStylesEnabled || this.BorderStyle != BorderStyle.Fixed3D) { return; } if (m.Msg == (int)WindowMessageFlags.WM_PRINT) { if ((m.LParam.ToInt32() & (int)WmPrintFlags.PRF_NONCLIENT) == (int)WmPrintFlags.PRF_NONCLIENT) { // open theme data IntPtr hTheme = UxTheme.OpenThemeData(this.Handle, UxTheme.WindowClasses.TreeView); if (hTheme != IntPtr.Zero) { // get the part and state needed int partId = (int)UxTheme.Parts.TreeView.TreeItem; int stateId = (int)UxTheme.PartStates.TreeItem.Normal; RECT rect = new RECT(); rect.right = this.Width; rect.bottom = this.Height; RECT clipRect = new RECT(); // draw the left border clipRect.left = rect.left; clipRect.top = rect.top; clipRect.right = rect.left + 2; clipRect.bottom = rect.bottom; UxTheme.DrawThemeBackground(hTheme, m.WParam, partId, stateId, ref rect, ref clipRect); // draw the top border clipRect.left = rect.left; clipRect.top = rect.top; clipRect.right = rect.right; clipRect.bottom = rect.top + 2; UxTheme.DrawThemeBackground(hTheme, m.WParam, partId, stateId, ref rect, ref clipRect); // draw the right border clipRect.left = rect.right - 2; clipRect.top = rect.top; clipRect.right = rect.right; clipRect.bottom = rect.bottom; UxTheme.DrawThemeBackground(hTheme, m.WParam, partId, stateId, ref rect, ref clipRect); // draw the bottom border clipRect.left = rect.left; clipRect.top = rect.bottom - 2; clipRect.right = rect.right; clipRect.bottom = rect.bottom; UxTheme.DrawThemeBackground(hTheme, m.WParam, partId, stateId, ref rect, ref clipRect); } UxTheme.CloseThemeData(hTheme); } } }