Exemplo n.º 1
0
            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                case NativeMethods.WM_PAINT:
                    if (!_bPainting)
                    {
                        NativeMethods1.PAINTSTRUCT ps =
                            new NativeMethods1.PAINTSTRUCT();
                        _bPainting = true;
                        NativeMethods1.BeginPaint(m.HWnd, ref ps);
                        DrawUpDownButton();
                        NativeMethods1.EndPaint(m.HWnd, ref ps);
                        _bPainting = false;
                        m.Result   = NativeMethods1.TRUE;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                default:
                    base.WndProc(ref m);
                    break;
                }
            }
Exemplo n.º 2
0
 private IntPtr FindUpDownButton()
 {
     return(NativeMethods1.FindWindowEx(
                base.Handle,
                IntPtr.Zero,
                UpDownButtonClassName,
                null));
 }
Exemplo n.º 3
0
 private bool LeftKeyPressed()
 {
     if (SystemInformation.MouseButtonsSwapped)
     {
         return(NativeMethods1.GetKeyState(NativeMethods1.VK_RBUTTON) < 0);
     }
     else
     {
         return(NativeMethods1.GetKeyState(NativeMethods1.VK_LBUTTON) < 0);
     }
 }
Exemplo n.º 4
0
            private void DrawUpDownButton()
            {
                bool mouseOver       = false;
                bool mousePress      = LeftKeyPressed();
                bool mouseInUpButton = false;

                NativeMethods1.RECT rect = new NativeMethods1.RECT();

                NativeMethods1.GetClientRect(base.Handle, ref rect);

                Rectangle clipRect = Rectangle.FromLTRB(
                    rect.Top, rect.Left, rect.Right, rect.Bottom);

                Point cursorPoint = new Point();

                NativeMethods1.GetCursorPos(ref cursorPoint);
                NativeMethods1.GetWindowRect(base.Handle, ref rect);

                mouseOver = NativeMethods1.PtInRect(ref rect, cursorPoint);

                cursorPoint.X -= rect.Left;
                cursorPoint.Y -= rect.Top;

                mouseInUpButton = cursorPoint.X < clipRect.Width / 2;

                using (Graphics g = Graphics.FromHwnd(base.Handle))
                {
                    UpDownButtonPaintEventArgs e =
                        new UpDownButtonPaintEventArgs(
                            g,
                            clipRect,
                            mouseOver,
                            mousePress,
                            mouseInUpButton);
                    _owner.OnPaintUpDownButton(e);
                }
            }
Exemplo n.º 5
0
        private void DrawBorder(Graphics g)
        {
            if (SelectedIndex != -1)
            {
                Rectangle tabRect  = GetTabRect(SelectedIndex);
                Rectangle clipRect = ClientRectangle;
                Point[]   points   = new Point[6];

                IntPtr upDownButtonHandle = UpDownButtonHandle;
                bool   hasUpDown          = upDownButtonHandle != IntPtr.Zero;
                if (hasUpDown)
                {
                    if (NativeMethods1.IsWindowVisible(upDownButtonHandle))
                    {
                        NativeMethods1.RECT upDownButtonRect = new NativeMethods1.RECT();
                        NativeMethods1.GetWindowRect(
                            upDownButtonHandle,
                            ref upDownButtonRect);
                        Rectangle upDownRect = Rectangle.FromLTRB(
                            upDownButtonRect.Left,
                            upDownButtonRect.Top,
                            upDownButtonRect.Right,
                            upDownButtonRect.Bottom);
                        upDownRect = RectangleToClient(upDownRect);

                        tabRect.X = tabRect.X > upDownRect.X ?
                                    upDownRect.X : tabRect.X;
                        tabRect.Width = tabRect.Right > upDownRect.X ?
                                        upDownRect.X - tabRect.X : tabRect.Width;
                    }
                }

                switch (Alignment)
                {
                case TabAlignment.Top:
                    points[0] = new Point(
                        tabRect.X,
                        tabRect.Bottom);
                    points[1] = new Point(
                        clipRect.X,
                        tabRect.Bottom);
                    points[2] = new Point(
                        clipRect.X,
                        clipRect.Bottom - 1);
                    points[3] = new Point(
                        clipRect.Right - 1,
                        clipRect.Bottom - 1);
                    points[4] = new Point(
                        clipRect.Right - 1,
                        tabRect.Bottom);
                    points[5] = new Point(
                        tabRect.Right,
                        tabRect.Bottom);
                    break;

                case TabAlignment.Bottom:
                    points[0] = new Point(
                        tabRect.X,
                        tabRect.Y);
                    points[1] = new Point(
                        clipRect.X,
                        tabRect.Y);
                    points[2] = new Point(
                        clipRect.X,
                        clipRect.Y);
                    points[3] = new Point(
                        clipRect.Right - 1,
                        clipRect.Y);
                    points[4] = new Point(
                        clipRect.Right - 1,
                        tabRect.Y);
                    points[5] = new Point(
                        tabRect.Right,
                        tabRect.Y);
                    break;

                case TabAlignment.Left:
                    points[0] = new Point(
                        tabRect.Right,
                        tabRect.Y);
                    points[1] = new Point(
                        tabRect.Right,
                        clipRect.Y);
                    points[2] = new Point(
                        clipRect.Right - 1,
                        clipRect.Y);
                    points[3] = new Point(
                        clipRect.Right - 1,
                        clipRect.Bottom - 1);
                    points[4] = new Point(
                        tabRect.Right,
                        clipRect.Bottom - 1);
                    points[5] = new Point(
                        tabRect.Right,
                        tabRect.Bottom);
                    break;

                case TabAlignment.Right:
                    points[0] = new Point(
                        tabRect.X,
                        tabRect.Y);
                    points[1] = new Point(
                        tabRect.X,
                        clipRect.Y);
                    points[2] = new Point(
                        clipRect.X,
                        clipRect.Y);
                    points[3] = new Point(
                        clipRect.X,
                        clipRect.Bottom - 1);
                    points[4] = new Point(
                        tabRect.X,
                        clipRect.Bottom - 1);
                    points[5] = new Point(
                        tabRect.X,
                        tabRect.Bottom);
                    break;
                }
                using (Pen pen = new Pen(_borderColor))
                {
                    g.DrawLines(pen, points);
                }
            }
        }
Exemplo n.º 6
0
        private void DrawTabPages(Graphics g)
        {
            Rectangle tabRect;
            Point     cusorPoint = PointToClient(MousePosition);
            bool      hover;
            bool      selected;
            bool      hasSetClip      = false;
            bool      alignHorizontal =
                (Alignment == TabAlignment.Top ||
                 Alignment == TabAlignment.Bottom);
            LinearGradientMode mode = alignHorizontal ?
                                      LinearGradientMode.Vertical : LinearGradientMode.Horizontal;

            if (alignHorizontal)
            {
                IntPtr upDownButtonHandle = UpDownButtonHandle;
                bool   hasUpDown          = upDownButtonHandle != IntPtr.Zero;
                if (hasUpDown)
                {
                    if (NativeMethods1.IsWindowVisible(upDownButtonHandle))
                    {
                        NativeMethods1.RECT upDownButtonRect = new NativeMethods1.RECT();
                        NativeMethods1.GetWindowRect(
                            upDownButtonHandle, ref upDownButtonRect);
                        Rectangle upDownRect = Rectangle.FromLTRB(
                            upDownButtonRect.Left,
                            upDownButtonRect.Top,
                            upDownButtonRect.Right,
                            upDownButtonRect.Bottom);
                        upDownRect = RectangleToClient(upDownRect);

                        switch (Alignment)
                        {
                        case TabAlignment.Top:
                            upDownRect.Y = 0;
                            break;

                        case TabAlignment.Bottom:
                            upDownRect.Y =
                                ClientRectangle.Height - DisplayRectangle.Height;
                            break;
                        }
                        upDownRect.Height = ClientRectangle.Height;
                        g.SetClip(upDownRect, CombineMode.Exclude);
                        hasSetClip = true;
                    }
                }
            }

            for (int index = 0; index < base.TabCount; index++)
            {
                TabPage page = TabPages[index];

                tabRect  = GetTabRect(index);
                hover    = tabRect.Contains(cusorPoint);
                selected = SelectedIndex == index;

                Color baseColor   = _baseColor;
                Color borderColor = _borderColor;

                if (selected)
                {
                    baseColor = GetColor(_baseColor, 0, -45, -30, -14);
                }
                else if (hover)
                {
                    baseColor = GetColor(_baseColor, 0, 35, 24, 9);
                }

                RenderTabBackgroundInternal(
                    g,
                    tabRect,
                    baseColor,
                    borderColor,
                    .45F,
                    mode);

                bool hasImage = DrawTabImage(g, page, tabRect);

                DrawtabText(g, page, tabRect, hasImage);
            }
            if (hasSetClip)
            {
                g.ResetClip();
            }
        }