Пример #1
0
        /// <summary>
        /// Draws the background image defined by the visual style for the specified control part
        /// </summary>
        /// <param name="g">The Graphics to draw on</param>
        /// <param name="windowClass">The class of the part to draw</param>
        /// <param name="part">The part to draw</param>
        /// <param name="partState">The state of the part to draw</param>
        /// <param name="drawRect">The Rectangle in which the part is drawn</param>
        /// <param name="clipRect">The Rectangle that represents the clipping area for the part</param>
        public static void DrawThemeBackground(Graphics g, string windowClass, int part, int partState, Rectangle drawRect, Rectangle clipRect)
        {
            if (g == null || drawRect.Width <= 0 || drawRect.Height <= 0 || clipRect.Width <= 0 || clipRect.Height <= 0)
            {
                return;
            }

            // open theme data
            IntPtr hTheme = IntPtr.Zero;

            hTheme = Win32API.OpenThemeData(hTheme, windowClass);

            // make sure we have a valid handle
            if (hTheme != IntPtr.Zero)
            {
                // get a graphics object the UxTheme can draw into
                IntPtr hdc = g.GetHdc();

                // get the draw and clipping rectangles
                RECT dRect = RECT.FromRectangle(drawRect);
                RECT cRect = RECT.FromRectangle(clipRect);

                // draw the themed background
                Win32API.DrawThemeBackground(hTheme, hdc, part, partState, ref dRect, ref cRect);

                // clean up resources
                g.ReleaseHdc(hdc);
            }

            // close the theme handle
            Win32API.CloseThemeData(hTheme);
        }