Пример #1
0
        private static bool DrawThemedTextBoxBorderNative(IntPtr hWnd, Graphics g, Rectangle bounds, TextBoxState style)
        {
            if (!VisualStyleRenderer.IsSupported)
            {
                return(false);
            }

            using (var themeData = CreateSafeThemeDataHandle(hWnd, VisualStyle.CLASS.EDIT))
            {
                if (themeData.IsInvalid)
                {
                    return(false);
                }

                var part  = VisualStyle.EDITPARTS.EP_EDITBORDER_NOSCROLL;
                var state = style == TextBoxState.Disabled ? VisualStyle.EDITBORDER_NOSCROLLSTATES.EPSN_DISABLED :
                            style == TextBoxState.Hot      ? VisualStyle.EDITBORDER_NOSCROLLSTATES.EPSN_HOT :
                            style == TextBoxState.Focused  ? VisualStyle.EDITBORDER_NOSCROLLSTATES.EPSN_FOCUSED :
                            VisualStyle.EDITBORDER_NOSCROLLSTATES.EPSN_NORMAL;

                using (var graphicsDeviceContext = new SafeGraphicsDeviceContextHandle(g))
                {
                    DrawThemeBackground(themeData, graphicsDeviceContext, part, state, bounds);
                }
            }

            return(true);
        }
Пример #2
0
        private static int DrawThemeBackground(SafeThemeDataHandle themeDataHandle,
                                               SafeGraphicsDeviceContextHandle graphicsDeviceContextHandle,
                                               VisualStyle.EDITPARTS editPart,
                                               VisualStyle.EDITBORDER_NOSCROLLSTATES state,
                                               RECT area)
        {
            var hTheme = themeDataHandle.DangerousGetHandle();
            var hdc    = graphicsDeviceContextHandle.DangerousGetHandle();

            var iPartId  = (int)editPart;
            var iStateId = (int)state;

            return(NativeMethods.DrawThemeBackground(hTheme, hdc, iPartId, iStateId, ref area, IntPtr.Zero));
        }