Exemple #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 = I3NativeMethods.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
                I3RECT dRect = I3RECT.FromRectangle(drawRect);
                I3RECT cRect = I3RECT.FromRectangle(clipRect);

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

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

            // close the theme handle
            I3NativeMethods.CloseThemeData(hTheme);
        }
        /// <summary>
        /// 响应垂直滚动条滚动事件
        /// Occurs when the Table's vertical scrollbar is scrolled
        /// </summary>
        /// <param name="sender">The object that Raised the event</param>
        /// <param name="e">A ScrollEventArgs that contains the event data</param>
        protected void OnVerticalScroll(object sender, ScrollEventArgs e)
        {
            int scrollVal = e.OldValue - e.NewValue;

            if (scrollVal != 0)
            {
                Rectangle invalidateRect = new Rectangle(0, 0, this.Width - VScrollWidth, this.Height - HScrollHeight);
                I3RECT    scrollRect     = I3RECT.FromRectangle(invalidateRect);

                scrollRect.top += 1;
                I3NativeMethods.ScrollWindow(this.Handle, 0, scrollVal, ref scrollRect, ref scrollRect);

                if (scrollVal < 0)
                {
                    invalidateRect.Y = invalidateRect.Bottom + scrollVal;
                }
                invalidateRect.Height = Math.Abs(scrollVal) + 1;

                this.Invalidate(invalidateRect, false);
            }
        }
        protected void OnHorizontalScroll(object sender, ScrollEventArgs e)
        {
            int scrollVal = e.OldValue - e.NewValue;

            if (scrollVal != 0)
            {
                Rectangle invalidateRect = new Rectangle(0, 0, this.Width - VScrollWidth, this.Height - HScrollHeight);
                I3RECT    scrollRect     = I3RECT.FromRectangle(invalidateRect);

                //移动窗体的绘画区
                I3NativeMethods.ScrollWindow(this.Handle, scrollVal, 0, ref scrollRect, ref scrollRect);

                //计算重绘区域
                if (scrollVal < 0)
                {
                    invalidateRect.X = invalidateRect.Right + scrollVal;
                }
                invalidateRect.Width = Math.Abs(scrollVal) + 1;

                this.Invalidate(invalidateRect, false);
            }
        }