public static void DrawButton (Graphics g, Rectangle bounds, string buttonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, PushButtonState state)
		{
			if (Application.RenderWithVisualStyles || always_use_visual_styles == true) {
				VisualStyleRenderer vsr = GetPushButtonRenderer (state);

				vsr.DrawBackground (g, bounds);

				if (image != null)
					vsr.DrawImage (g, imageBounds, image);
			} else {
				if (state == PushButtonState.Pressed)
					ControlPaint.DrawButton (g, bounds, ButtonState.Pushed);
				else
					ControlPaint.DrawButton (g, bounds, ButtonState.Normal);

				if (image != null)
					g.DrawImage (image, imageBounds);
			}

			Rectangle focus_rect = bounds;
			focus_rect.Inflate (-3, -3);

			if (focused)
				ControlPaint.DrawFocusRectangle (g, focus_rect);

			if (buttonText != String.Empty)
				if (state == PushButtonState.Disabled)
					TextRenderer.DrawText (g, buttonText, font, focus_rect, SystemColors.GrayText, flags);
				else
					TextRenderer.DrawText (g, buttonText, font, focus_rect, SystemColors.ControlText, flags);
		}
Example #2
0
	   protected override void OnGotFocus(EventArgs e) {
		  if (!showSplit) {
			 base.OnGotFocus(e);
			 return;
		  }

		  if (!State.Equals(PushButtonState.Pressed) && !State.Equals(PushButtonState.Disabled)) {
			 State = PushButtonState.Default;
		  }
	   }
Example #3
0
        /// <include file='doc\ButtonRenderer.uex' path='docs/doc[@for="ButtonRenderer.IsBackgroundPartiallyTransparent"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Returns true if the background corresponding to the given state is partially transparent, else false.
        ///    </para>
        /// </devdoc>
        public static bool IsBackgroundPartiallyTransparent(PushButtonState state) {
            if (RenderWithVisualStyles) {
                InitializeRenderer((int)state);

                return visualStyleRenderer.IsBackgroundPartiallyTransparent();
            }
            else {
                return false; //for downlevel, this is false
            }
        }
Example #4
0
	   protected override void OnKeyDown(KeyEventArgs kevent) {
		  if (showSplit) {
			 if (kevent.KeyCode.Equals(Keys.Down)) {
				ShowContextMenuStrip();
			 } else if (kevent.KeyCode.Equals(Keys.Space) && kevent.Modifiers == Keys.None) {
				State = PushButtonState.Pressed;
			 }
		  }

		  base.OnKeyDown(kevent);
	   }
 public static void DrawButton(Graphics g, Rectangle bounds, PushButtonState state)
 {
     if (RenderWithVisualStyles)
     {
         InitializeRenderer((int) state);
         visualStyleRenderer.DrawBackground(g, bounds);
     }
     else
     {
         ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
     }
 }
        private bool _enabled; // Is the button enabled

        #endregion Fields

        #region Constructors

        protected DataGridViewImageButtonCell()
        {
            // In my project, buttons are disabled by default
            _enabled = false;
            _buttonState = PushButtonState.Disabled;

            // Changing this value affects the appearance of the image on the button.
            _buttonImageOffset = 2;

            // Call the routine to load the images specific to a column.
            LoadImages();
        }
        internal static ButtonState ConvertToButtonState(PushButtonState state)
        {
            switch (state)
            {
                case PushButtonState.Pressed:
                    return ButtonState.Pushed;

                case PushButtonState.Disabled:
                    return ButtonState.Inactive;
            }
            return ButtonState.Normal;
        }
		public DataGridViewCheckBoxCell ()
		{
			check_state = PushButtonState.Normal;
			editingCellFormattedValue = false;
			editingCellValueChanged = false;
			falseValue = null;
			flatStyle = FlatStyle.Standard;
			indeterminateValue = null;
			threeState = false;
			trueValue = null;
			ValueType = null;
		}
        private bool _enabled; // Is the button enabled

        #endregion Fields

        #region Constructors

        protected DataGridViewImageButtonCell()
        {
            // In my project, buttons are disabled by default
            font = new Font("Arial", 8);
            _enabled = true;
            _buttonState= PushButtonState.Normal;

            // Changing this value affects the appearance of the image on the button.
            _buttonImageOffset = 4;

            // Call the routine to load the images specific to a column.
            LoadImages();
        }
 public static void DrawButton(Graphics g, Rectangle bounds, bool focused, PushButtonState state)
 {
     Rectangle backgroundContentRectangle;
     if (RenderWithVisualStyles)
     {
         InitializeRenderer((int) state);
         visualStyleRenderer.DrawBackground(g, bounds);
         backgroundContentRectangle = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds);
     }
     else
     {
         ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
         backgroundContentRectangle = Rectangle.Inflate(bounds, -3, -3);
     }
     if (focused)
     {
         ControlPaint.DrawFocusRectangle(g, backgroundContentRectangle);
     }
 }
Example #11
0
    private void ShowContextMenuStrip()
    {
        if (skipNextOpen)
        {
            // we were called because we're closing the context menu strip
            // when clicking the dropdown button.
            skipNextOpen = false;
            return;
        }

        State = PushButtonState.Pressed;

        if (m_SplitMenu != null)
        {
            m_SplitMenu.Show(this, new Point(0, Height));
        }
        else if (m_SplitMenuStrip != null)
        {
            m_SplitMenuStrip.Show(this, new Point(0, Height), ToolStripDropDownDirection.BelowRight);
        }
    }
Example #12
0
        protected override void OnMouseLeave(EventArgs e)
        {
            if (!showSplit)
            {
                base.OnMouseLeave(e);
                return;
            }

            if (!State.Equals(PushButtonState.Pressed) && !State.Equals(PushButtonState.Disabled))
            {
                if (Focused)
                {
                    State = PushButtonState.Default;
                }

                else
                {
                    State = PushButtonState.Normal;
                }
            }
        }
Example #13
0
 public static void DrawButton(
     Graphics g,
     Rectangle bounds,
     string buttonText,
     Font font,
     Image image,
     Rectangle imageBounds,
     bool focused,
     PushButtonState state)
 {
     DrawButton(
         g,
         bounds,
         buttonText,
         font,
         TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine,
         image,
         imageBounds,
         focused,
         state);
 }
Example #14
0
        internal static VisualStyleRenderer GetPushButtonRenderer(PushButtonState state)
        {
            switch (state)
            {
            case PushButtonState.Normal:
                return(new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal));

            case PushButtonState.Hot:
                return(new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot));

            case PushButtonState.Pressed:
                return(new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Pressed));

            case PushButtonState.Disabled:
                return(new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Disabled));

            case PushButtonState.Default:
            default:
                return(new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Default));
            }
        }
Example #15
0
        internal static void DrawButton(
            IDeviceContext deviceContext,
            Rectangle bounds,
            string buttonText,
            Font font,
            TextFormatFlags flags,
            Image image,
            Rectangle imageBounds,
            bool focused,
            PushButtonState state)
        {
            Rectangle contentBounds;
            Color     textColor;

            Graphics graphics = deviceContext.TryGetGraphics(create: true);

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                t_visualStyleRenderer.DrawBackground(deviceContext, bounds);
                t_visualStyleRenderer.DrawImage(graphics, imageBounds, image);
                contentBounds = t_visualStyleRenderer.GetBackgroundContentRectangle(deviceContext, bounds);
                textColor     = t_visualStyleRenderer.GetColor(ColorProperty.TextColor);
            }
            else
            {
                ControlPaint.DrawButton(graphics, bounds, ConvertToButtonState(state));
                graphics.DrawImage(image, imageBounds);
                contentBounds = Rectangle.Inflate(bounds, -3, -3);
                textColor     = SystemColors.ControlText;
            }

            TextRenderer.DrawText(deviceContext, buttonText, font, contentBounds, textColor, flags);

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(graphics, contentBounds);
            }
        }
        /// <include file='doc\ButtonRenderer.uex' path='docs/doc[@for="ButtonRenderer.DrawButton1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Renders a Button control.
        ///    </para>
        /// </devdoc>
        public static void DrawButton(Graphics g, Rectangle bounds, bool focused, PushButtonState state)
        {
            Rectangle contentBounds;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                visualStyleRenderer.DrawBackground(g, bounds);
                contentBounds = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds);
            }
            else
            {
                ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
                contentBounds = Rectangle.Inflate(bounds, -3, -3);
            }

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, contentBounds);
            }
        }
Example #17
0
        private void ShowContextMenuStrip()
        {
            if (m_skipNextOpen)
            {
                // we were called because we're closing the context menu strip
                // when clicking the dropdown button.
                m_skipNextOpen = false;
                return;
            }

            //expose an opportunity to modify the context menu
            ContextMenuShowing?.ThreadSafeInvoke(this, EventArgs.Empty);

            State = PushButtonState.Pressed;
            if (ContextMenuStrip == null)
            {
                return;
            }

            ContextMenuStrip.Closing += ContextMenuStrip_Closing;
            ContextMenuStrip.Show(this, new Point(0, Height), ToolStripDropDownDirection.BelowRight);
        }
        private PushButtonState DetermineState(bool up)
        {
            PushButtonState normal = PushButtonState.Normal;

            if (!up)
            {
                return(PushButtonState.Pressed);
            }
            if (base.Control.MouseIsOver)
            {
                return(PushButtonState.Hot);
            }
            if (!base.Control.Enabled)
            {
                return(PushButtonState.Disabled);
            }
            if (!base.Control.Focused && !base.Control.IsDefault)
            {
                return(normal);
            }
            return(PushButtonState.Default);
        }
Example #19
0
        private void PaintThemedButtonBackground(PaintEventArgs e, Rectangle bounds)
        {
            PushButtonState state = State;

            if (ButtonRenderer.IsBackgroundPartiallyTransparent(state))
            {
                ButtonRenderer.DrawParentBackground(e.Graphics, bounds, this);
            }
            ButtonRenderer.DrawButton(e.Graphics, ClientRectangle, false, state);

            if (!UseVisualStyleBackColor)
            {
                if (Application.RenderWithVisualStyles)
                {
                    bounds.Inflate(-BorderSize, -BorderSize);
                }
                else
                {
                    bounds.X      += 1;
                    bounds.Y      += 1;
                    bounds.Width  -= 3;
                    bounds.Height -= 3;
                }

                Color backColor = BackColor;
                if (backColor.A > 0)
                {
                    if (backColor.A == 0xff)
                    {
                        backColor = e.Graphics.GetNearestColor(backColor);
                    }
                    using (Brush brush = new SolidBrush(backColor))
                    {
                        e.Graphics.FillRectangle(brush, bounds);
                    }
                }
            }
        }
Example #20
0
        private void ShowContextMenuStrip()
        {
            if (skipNextOpen)
            {
                // we were called because we're closing the context menu strip
                // when clicking the dropdown button.
                skipNextOpen = false;
                return;
            }

            if (OnBeforeSplitDropdownDisplayed != null)
            {
                OnBeforeSplitDropdownDisplayed(this, new EventArgs());
            }

            State = PushButtonState.Pressed;

            if (ContextMenuStrip != null)
            {
                ContextMenuStrip.Closing += new ToolStripDropDownClosingEventHandler(ContextMenuStrip_Closing);
                ContextMenuStrip.Show(this, new Point(0, Height), ToolStripDropDownDirection.BelowRight);
            }
        }
Example #21
0
        /// <summary>
        /// Affiche le menu contextuel
        /// </summary>
        private void ShowContextMenuStrip()
        {
            if (skipNextOpen)
            {
                // we were called because we're closing the context menu strip
                // when clicking the dropdown button.
                skipNextOpen = false;
                return;
            }
            State = PushButtonState.Pressed;

            if (ContextMenuStrip != null)
            {
                ContextMenuStrip.Closing += ContextMenuStrip_Closing;
                ContextMenuStrip.Show(this, new Point(0, Height), ToolStripDropDownDirection.BelowRight);
            }
            //else {
            //    if (this.ContextItems.Count > 0) {
            //        this.contextMenu.Closing += new ToolStripDropDownClosingEventHandler(ContextMenuStrip_Closing);
            //        this.contextMenu.Show(this, new Point(0, Height), ToolStripDropDownDirection.BelowRight);
            //    }
            //}
        }
Example #22
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!showSplit)
            {
                base.OnMouseDown(e);
                return;
            }

            //handle ContextMenu re-clicking the drop-down region to close the menu
            if (m_SplitMenu != null && e.Button == MouseButtons.Left && !isMouseEntered)
            {
                skipNextOpen = true;
            }

            if (dropDownRectangle.Contains(e.Location) && !isSplitMenuVisible && e.Button == MouseButtons.Left)
            {
                ShowContextMenuStrip();
            }
            else
            {
                State = PushButtonState.Pressed;
            }
        }
        private PushButtonState DetermineState(bool up)
        {
            PushButtonState state = PushButtonState.Normal;

            if (!up)
            {
                state = PushButtonState.Pressed;
            }
            else if (Control.MouseIsOver)
            {
                state = PushButtonState.Hot;
            }
            else if (!Control.Enabled)
            {
                state = PushButtonState.Disabled;
            }
            else if (Control.Focused || Control.IsDefault)
            {
                state = PushButtonState.Default;
            }

            return(state);
        }
Example #24
0
        /// <summary>
        ///  Method to draw visualstyle themes in case of per-monitor scenarios where Hwnd is necessary
        /// </summary>
        /// <param name="hwnd"> handle to the control</param>
        internal static void DrawButtonForHandle(
            IDeviceContext deviceContext,
            Rectangle bounds,
            bool focused,
            PushButtonState state,
            IntPtr hwnd)
        {
            Rectangle contentBounds;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                using var hdc = new DeviceContextHdcScope(deviceContext);
                t_visualStyleRenderer.DrawBackground(hdc, bounds, hwnd);
                contentBounds = t_visualStyleRenderer.GetBackgroundContentRectangle(hdc, bounds);
            }
            else
            {
                Graphics?graphics = deviceContext.TryGetGraphics(create: true);
                if (graphics is not null)
                {
                    ControlPaint.DrawButton(graphics, bounds, ConvertToButtonState(state));
                }

                contentBounds = Rectangle.Inflate(bounds, -3, -3);
            }

            if (focused)
            {
                Graphics?graphics = deviceContext.TryGetGraphics(create: true);
                if (graphics is not null)
                {
                    ControlPaint.DrawFocusRectangle(graphics, contentBounds);
                }
            }
        }
        private void PaintThemedButtonBackground(PaintEventArgs e, Rectangle bounds, bool up)
        {
            PushButtonState state = this.DetermineState(up);

            if (ButtonRenderer.IsBackgroundPartiallyTransparent(state))
            {
                ButtonRenderer.DrawParentBackground(e.Graphics, bounds, base.Control);
            }
            ButtonRenderer.DrawButton(e.Graphics, base.Control.ClientRectangle, false, state);
            bounds.Inflate(-ButtonBaseAdapter.buttonBorderSize, -ButtonBaseAdapter.buttonBorderSize);
            if (!base.Control.UseVisualStyleBackColor)
            {
                bool  flag      = false;
                Color backColor = base.Control.BackColor;
                if (((backColor.A == 0xff) && (e.HDC != IntPtr.Zero)) && (DisplayInformation.BitsPerPixel > 8))
                {
                    System.Windows.Forms.NativeMethods.RECT rect = new System.Windows.Forms.NativeMethods.RECT(bounds.X, bounds.Y, bounds.Right, bounds.Bottom);
                    System.Windows.Forms.SafeNativeMethods.FillRect(new HandleRef(e, e.HDC), ref rect, new HandleRef(this, base.Control.BackColorBrush));
                    flag = true;
                }
                if (!flag && (backColor.A > 0))
                {
                    if (backColor.A == 0xff)
                    {
                        backColor = e.Graphics.GetNearestColor(backColor);
                    }
                    using (Brush brush = new SolidBrush(backColor))
                    {
                        e.Graphics.FillRectangle(brush, bounds);
                    }
                }
            }
            if ((base.Control.BackgroundImage != null) && !DisplayInformation.HighContrast)
            {
                ControlPaint.DrawBackgroundImage(e.Graphics, base.Control.BackgroundImage, Color.Transparent, base.Control.BackgroundImageLayout, base.Control.ClientRectangle, bounds, base.Control.DisplayRectangle.Location, base.Control.RightToLeft);
            }
        }
Example #26
0
        protected override void OnMouseUp(MouseEventArgs mevent)
        {
            if (ContextMenuStrip == null || !ContextMenuStrip.Visible)
            {
                if (Bounds.Contains(Parent.PointToClient(Cursor.Position)))
                {
                    m_State = PushButtonState.Hot;
                }
                else if (Focused)
                {
                    m_State = PushButtonState.Default;
                }
                else
                {
                    m_State = PushButtonState.Normal;
                }

                if (Bounds.Contains(Parent.PointToClient(Cursor.Position)) && !m_SplitButtonRectangle.Contains(mevent.Location))
                {
                    OnClick(new EventArgs());
                }
                Invalidate();
            }
        }
Example #27
0
        public void DrawScrollButtons(Graphics g, Rectangle bounds, Point Mouselocation, Point MouseClicking, bool Cross, bool Enabled)
        {
            Rectangle Arrows = GenerateArrowBounds(bounds, Cross);

            Arrows = new Rectangle(Arrows.X, Arrows.Y, Arrows.Width, bounds.Height);
            g.FillRectangle(SystemBrushes.Control, Arrows);

            PushButtonState state_left  = PushButtonState.Normal;
            PushButtonState state_right = PushButtonState.Normal;

            if (ArrowLeft.Contains(Mouselocation))
            {
                state_left = PushButtonState.Hot;
            }
            if (ArrowRight.Contains(Mouselocation))
            {
                state_right = PushButtonState.Hot;
            }
            if (ArrowLeft.Contains(MouseClicking))
            {
                state_left = PushButtonState.Pressed;
            }
            if (ArrowRight.Contains(MouseClicking))
            {
                state_right = PushButtonState.Pressed;
            }
            if (!Enabled)
            {
                state_left  = PushButtonState.Disabled;
                state_right = PushButtonState.Disabled;
            }
            ButtonRenderer.DrawButton(g, ArrowLeft, state_left);
            ButtonRenderer.DrawButton(g, ArrowRight, state_right);
            g.DrawString("<", SystemFonts.DialogFont, SystemBrushes.ControlText, new Point(arrow_left.X + 3, arrow_left.Y + 3));
            g.DrawString(">", SystemFonts.DialogFont, SystemBrushes.ControlText, new Point(arrow_right.X + 3, arrow_right.Y + 3));
        }
Example #28
0
        protected override void OnEnabledChanged(EventArgs e)
        {
            State = Enabled ? PushButtonState.Normal : PushButtonState.Disabled;

            base.OnEnabledChanged(e);
        }
Example #29
0
		private void MouseDownHandler (object sender, MouseEventArgs e)
		{
			if ((e.Button & MouseButtons.Left) == 0)
				return;

			if (ShowSlider) {
				Rectangle right = RightScrollButtonArea;
				Rectangle left = LeftScrollButtonArea;
				if (right.Contains (e.X, e.Y)) {
					right_slider_state = PushButtonState.Pressed;
					if (CanScrollRight) {
						slider_pos++;
						SizeTabs ();

						// UIA Framework Event: Horizontally Scrolled
						OnUIAHorizontallyScrolled (EventArgs.Empty);

						switch (this.Alignment) {
							case TabAlignment.Top:
								Invalidate (new Rectangle (0, 0, Width, ItemSize.Height));
								break;
							case TabAlignment.Bottom:
								Invalidate (new Rectangle (0, DisplayRectangle.Bottom, Width, Height - DisplayRectangle.Bottom));
								break;
							case TabAlignment.Left:
								Invalidate (new Rectangle (0, 0, DisplayRectangle.Left, Height));
								break;
							case TabAlignment.Right:
								Invalidate (new Rectangle (DisplayRectangle.Right, 0, Width - DisplayRectangle.Right, Height));
								break;
						}
						
					} else {
						Invalidate (right);
					}
					return;
				} else if (left.Contains (e.X, e.Y)) {
					left_slider_state = PushButtonState.Pressed;
					if (CanScrollLeft) {
						slider_pos--;
						SizeTabs ();

						// UIA Framework Event: Horizontally Scrolled
						OnUIAHorizontallyScrolled (EventArgs.Empty);

						switch (this.Alignment) {
							case TabAlignment.Top:
								Invalidate (new Rectangle (0, 0, Width, ItemSize.Height));
								break;
							case TabAlignment.Bottom:
								Invalidate (new Rectangle (0, DisplayRectangle.Bottom, Width, Height - DisplayRectangle.Bottom));
								break;
							case TabAlignment.Left:
								Invalidate (new Rectangle (0, 0, DisplayRectangle.Left, Height));
								break;
							case TabAlignment.Right:
								Invalidate (new Rectangle (DisplayRectangle.Right, 0, Width - DisplayRectangle.Right, Height));
								break;
						}
					} else {
						Invalidate (left);
					}
					return;
				}
			}

			int count = Controls.Count;
			for (int i = SliderPos; i < count; i++) {
				if (!GetTabRect (i).Contains (e.X, e.Y))
					continue;
				SelectedIndex = i;
				mouse_down_on_a_tab_page = true;
				break;
			}
		}
Example #30
0
        public static void DrawButton(Graphics g, Rectangle bounds, string buttonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, PushButtonState state)
        {
            if (Application.RenderWithVisualStyles || always_use_visual_styles == true)
            {
                VisualStyleRenderer vsr = GetPushButtonRenderer(state);

                vsr.DrawBackground(g, bounds);

                if (image != null)
                {
                    vsr.DrawImage(g, imageBounds, image);
                }
            }
            else
            {
                if (state == PushButtonState.Pressed)
                {
                    ControlPaint.DrawButton(g, bounds, ButtonState.Pushed);
                }
                else
                {
                    ControlPaint.DrawButton(g, bounds, ButtonState.Normal);
                }

                if (image != null)
                {
                    g.DrawImage(image, imageBounds);
                }
            }

            Rectangle focus_rect = bounds;

            focus_rect.Inflate(-3, -3);

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, focus_rect);
            }

            if (buttonText != String.Empty)
            {
                if (state == PushButtonState.Disabled)
                {
                    TextRenderer.DrawText(g, buttonText, font, focus_rect, SystemColors.GrayText, flags);
                }
                else
                {
                    TextRenderer.DrawText(g, buttonText, font, focus_rect, SystemColors.ControlText, flags);
                }
            }
        }
Example #31
0
 /// <summary>
 ///  Renders a Button control.
 /// </summary>
 public static void DrawButton(Graphics g, Rectangle bounds, bool focused, PushButtonState state)
 {
     DrawButtonForHandle(g, bounds, focused, state, IntPtr.Zero);
 }
 public virtual void DrawDropDownButton(Graphics surface, DropDownButtonRenderingArgs args, PushButtonState state)
 {
     DrawButton(surface, args, state);
     DrawArrow(surface, args, state);
 }
Example #33
0
 public static void DrawButton(Graphics g, Rectangle bounds, Image image, Rectangle imageBounds, bool focused, PushButtonState state)
 {
     DrawButton(g, bounds, String.Empty, null, TextFormatFlags.Default, image, imageBounds, focused, state);
 }
        private void ShowContextMenuStrip()
        {
            if (skipNextOpen)
            {
                // we were called because we're closing the context menu strip
                // when clicking the dropdown button.
                skipNextOpen = false;
                return;
            }

            State = PushButtonState.Pressed;

            if (m_SplitMenuStrip != null)
            {
                m_SplitMenuStrip.Show(this, new Point(0, Height), ToolStripDropDownDirection.BelowRight);
            }
        }
Example #35
0
 /// <summary>
 /// Draws a push button in the specified state, on the specified graphics 
 /// surface, and within the specified bounds
 /// </summary>
 /// <param name="g">The Graphics to draw on</param>
 /// <param name="buttonRect">The Rectangle that represents the dimensions 
 /// of the button</param>
 /// <param name="state">A PushButtonState value that specifies the 
 /// state to draw the button in</param>
 /// <param name="flatStyle">If true, then the button is drawn in flat style, but only if VisualStyles are not being used.</param>
 public static void DrawButton(Graphics g, Rectangle buttonRect, PushButtonState state, bool flatStyle)
 {
     ThemeManager.DrawButton(g, buttonRect, buttonRect, state, flatStyle);
 }
Example #36
0
        private Rectangle PaintPrivate(Graphics g,
                                       Rectangle clipBounds,
                                       Rectangle cellBounds,
                                       int rowIndex,
                                       DataGridViewElementStates elementState,
                                       object formattedValue,
                                       string errorText,
                                       DataGridViewCellStyle cellStyle,
                                       DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                       DataGridViewPaintParts paintParts,
                                       bool computeContentBounds,
                                       bool computeErrorIconBounds,
                                       bool paint)
        {
            // Parameter checking.
            // One bit and one bit only should be turned on
            Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
            Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);
            Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint);
            Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds);
            Debug.Assert(cellStyle != null);

            Point ptCurrentCell = DataGridView.CurrentCellAddress;
            bool  cellSelected  = (elementState & DataGridViewElementStates.Selected) != 0;
            bool  cellCurrent   = (ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex);

            Rectangle resultBounds;
            string    formattedString = formattedValue as string;

            SolidBrush backBrush = DataGridView.GetCachedBrush((PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
            SolidBrush foreBrush = DataGridView.GetCachedBrush(cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor);

            if (paint && PaintBorder(paintParts))
            {
                PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }

            Rectangle valBounds    = cellBounds;
            Rectangle borderWidths = BorderWidths(advancedBorderStyle);

            valBounds.Offset(borderWidths.X, borderWidths.Y);
            valBounds.Width  -= borderWidths.Right;
            valBounds.Height -= borderWidths.Bottom;

            if (valBounds.Height <= 0 || valBounds.Width <= 0)
            {
                return(Rectangle.Empty);
            }

            if (paint && PaintBackground(paintParts) && backBrush.Color.A == 255)
            {
                g.FillRectangle(backBrush, valBounds);
            }

            if (cellStyle.Padding != Padding.Empty)
            {
                if (DataGridView.RightToLeftInternal)
                {
                    valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                valBounds.Width  -= cellStyle.Padding.Horizontal;
                valBounds.Height -= cellStyle.Padding.Vertical;
            }

            Rectangle errorBounds = valBounds;

            if (valBounds.Height > 0 && valBounds.Width > 0 && (paint || computeContentBounds))
            {
                switch (FlatStyle)
                {
                case FlatStyle.Standard:
                case FlatStyle.System:
                    if (DataGridView.ApplyVisualStylesToInnerCells)
                    {
                        if (paint && PaintContentBackground(paintParts))
                        {
                            PushButtonState pbState = VisualStyles.PushButtonState.Normal;
                            if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0)
                            {
                                pbState = PushButtonState.Pressed;
                            }
                            else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
                                     DataGridView.MouseEnteredCellAddress.X == ColumnIndex && mouseInContentBounds)
                            {
                                pbState = PushButtonState.Hot;
                            }

                            if (PaintFocus(paintParts) && cellCurrent && DataGridView.ShowFocusCues && DataGridView.Focused)
                            {
                                pbState |= PushButtonState.Default;
                            }

                            DataGridViewButtonCellRenderer.DrawButton(g, valBounds, (int)pbState);
                        }

                        resultBounds = valBounds;
                        valBounds    = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetBackgroundContentRectangle(g, valBounds);
                    }
                    else
                    {
                        if (paint && PaintContentBackground(paintParts))
                        {
                            ControlPaint.DrawBorder(
                                g,
                                valBounds,
                                SystemColors.Control,
                                (ButtonState == ButtonState.Normal) ? ButtonBorderStyle.Outset : ButtonBorderStyle.Inset);
                        }
                        resultBounds = valBounds;
                        valBounds.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height);
                    }

                    break;

                case FlatStyle.Flat:
                    // ButtonBase::PaintFlatDown and ButtonBase::PaintFlatUp paint the border in the same way
                    valBounds.Inflate(-1, -1);
                    if (paint && PaintContentBackground(paintParts))
                    {
                        ButtonBaseAdapter.DrawDefaultBorder(g, valBounds, foreBrush.Color, true /*isDefault == true*/);

                        if (backBrush.Color.A == 255)
                        {
                            if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0)
                            {
                                ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintFlatRender(
                                    g,
                                    cellStyle.ForeColor,
                                    cellStyle.BackColor,
                                    DataGridView.Enabled).Calculate();

                                using var hdc    = new DeviceContextHdcScope(g);
                                using var hbrush = new Gdi32.CreateBrushScope(
                                          colors.options.HighContrast ? colors.buttonShadow : colors.lowHighlight);
                                hdc.FillRectangle(valBounds, hbrush);
                            }
                            else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
                                     DataGridView.MouseEnteredCellAddress.X == ColumnIndex && mouseInContentBounds)
                            {
                                using var hdc    = new DeviceContextHdcScope(g);
                                using var hbrush = new Gdi32.CreateBrushScope(SystemColors.ControlDark);
                                hdc.FillRectangle(valBounds, hbrush);
                            }
                        }
                    }

                    resultBounds = valBounds;
                    break;

                default:
                    Debug.Assert(FlatStyle == FlatStyle.Popup, "FlatStyle.Popup is the last flat style");
                    valBounds.Inflate(-1, -1);
                    if (paint && PaintContentBackground(paintParts))
                    {
                        if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0)
                        {
                            // paint down
                            ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(
                                g,
                                cellStyle.ForeColor,
                                cellStyle.BackColor,
                                DataGridView.Enabled).Calculate();
                            ButtonBaseAdapter.DrawDefaultBorder(
                                g,
                                valBounds,
                                colors.options.HighContrast ? colors.windowText : colors.windowFrame,
                                isDefault: true);
                            ControlPaint.DrawBorder(
                                g,
                                valBounds,
                                colors.options.HighContrast ? colors.windowText : colors.buttonShadow,
                                ButtonBorderStyle.Solid);
                        }
                        else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
                                 DataGridView.MouseEnteredCellAddress.X == ColumnIndex &&
                                 mouseInContentBounds)
                        {
                            // paint over
                            ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(
                                g,
                                cellStyle.ForeColor,
                                cellStyle.BackColor,
                                DataGridView.Enabled).Calculate();
                            ButtonBaseAdapter.DrawDefaultBorder(
                                g,
                                valBounds,
                                colors.options.HighContrast ? colors.windowText : colors.buttonShadow,
                                isDefault: false);
                            ButtonBaseAdapter.Draw3DLiteBorder(g, valBounds, colors, true);
                        }
                        else
                        {
                            // paint up
                            ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(
                                g,
                                cellStyle.ForeColor,
                                cellStyle.BackColor,
                                DataGridView.Enabled).Calculate();
                            ButtonBaseAdapter.DrawDefaultBorder(
                                g,
                                valBounds,
                                colors.options.HighContrast ? colors.windowText : colors.buttonShadow,
                                isDefault: false);
                            ControlPaint.DrawBorderSolid(
                                g,
                                valBounds,
                                colors.options.HighContrast ? colors.windowText : colors.buttonShadow);
                        }
                    }

                    resultBounds = valBounds;
                    break;
                }
            }
            else if (computeErrorIconBounds)
            {
                if (!string.IsNullOrEmpty(errorText))
                {
                    resultBounds = ComputeErrorIconBounds(errorBounds);
                }
                else
                {
                    resultBounds = Rectangle.Empty;
                }
            }
            else
            {
                Debug.Assert(valBounds.Height <= 0 || valBounds.Width <= 0);
                resultBounds = Rectangle.Empty;
            }

            if (paint &&
                PaintFocus(paintParts) &&
                cellCurrent &&
                DataGridView.ShowFocusCues &&
                DataGridView.Focused &&
                valBounds.Width > 2 * SystemInformation.Border3DSize.Width + 1 &&
                valBounds.Height > 2 * SystemInformation.Border3DSize.Height + 1)
            {
                // Draw focus rectangle
                if (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard)
                {
                    ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(valBounds, -1, -1), Color.Empty, SystemColors.Control);
                }
                else if (FlatStyle == FlatStyle.Flat)
                {
                    if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 ||
                        (DataGridView.CurrentCellAddress.Y == rowIndex && DataGridView.CurrentCellAddress.X == ColumnIndex))
                    {
                        ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintFlatRender(
                            g,
                            cellStyle.ForeColor,
                            cellStyle.BackColor,
                            DataGridView.Enabled).Calculate();

                        string text = formattedString ?? string.Empty;

                        ButtonBaseAdapter.LayoutOptions options = ButtonFlatAdapter.PaintFlatLayout(
                            true,
                            SystemInformation.HighContrast,
                            1,
                            valBounds,
                            Padding.Empty,
                            false,
                            cellStyle.Font,
                            text,
                            DataGridView.Enabled,
                            DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment),
                            DataGridView.RightToLeft);
                        options.everettButtonCompat = false;
                        ButtonBaseAdapter.LayoutData layout = options.Layout();

                        ButtonBaseAdapter.DrawFlatFocus(
                            g,
                            layout.focus,
                            colors.options.HighContrast ? colors.windowText : colors.constrastButtonShadow);
                    }
                }
                else
                {
                    Debug.Assert(FlatStyle == FlatStyle.Popup, "FlatStyle.Popup is the last flat style");
                    if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 ||
                        (DataGridView.CurrentCellAddress.Y == rowIndex && DataGridView.CurrentCellAddress.X == ColumnIndex))
                    {
                        // If we are painting the current cell, then paint the text up.
                        // If we are painting the current cell and the current cell is pressed down, then paint the text down.
                        bool   paintUp = (ButtonState == ButtonState.Normal);
                        string text    = formattedString ?? string.Empty;
                        ButtonBaseAdapter.LayoutOptions options = ButtonPopupAdapter.PaintPopupLayout(
                            paintUp,
                            SystemInformation.HighContrast ? 2 : 1,
                            valBounds,
                            Padding.Empty,
                            false,
                            cellStyle.Font,
                            text,
                            DataGridView.Enabled,
                            DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment),
                            DataGridView.RightToLeft);
                        options.everettButtonCompat = false;
                        ButtonBaseAdapter.LayoutData layout = options.Layout();

                        ControlPaint.DrawFocusRectangle(
                            g,
                            layout.focus,
                            cellStyle.ForeColor,
                            cellStyle.BackColor);
                    }
                }
            }

            if (formattedString != null && paint && DataGridViewCell.PaintContentForeground(paintParts))
            {
                // Font independent margins
                valBounds.Offset(DATAGRIDVIEWBUTTONCELL_horizontalTextMargin, DATAGRIDVIEWBUTTONCELL_verticalTextMargin);
                valBounds.Width  -= 2 * DATAGRIDVIEWBUTTONCELL_horizontalTextMargin;
                valBounds.Height -= 2 * DATAGRIDVIEWBUTTONCELL_verticalTextMargin;

                if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 &&
                    FlatStyle != FlatStyle.Flat && FlatStyle != FlatStyle.Popup)
                {
                    valBounds.Offset(1, 1);
                    valBounds.Width--;
                    valBounds.Height--;
                }

                if (valBounds.Width > 0 && valBounds.Height > 0)
                {
                    Color textColor;
                    if (DataGridView.ApplyVisualStylesToInnerCells &&
                        (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard))
                    {
                        textColor = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetColor(ColorProperty.TextColor);
                    }
                    else
                    {
                        textColor = foreBrush.Color;
                    }
                    TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                    TextRenderer.DrawText(g,
                                          formattedString,
                                          cellStyle.Font,
                                          valBounds,
                                          textColor,
                                          flags);
                }
            }

            if (DataGridView.ShowCellErrors && paint && PaintErrorIcon(paintParts))
            {
                PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, errorBounds, errorText);
            }

            return(resultBounds);
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            if (!showSplit)
            {
                base.OnMouseLeave(e);
                return;
            }

            isMouseEntered = false;

            if (!State.Equals(PushButtonState.Pressed) && !State.Equals(PushButtonState.Disabled))
            {
                if (Focused)
                {
                    State = PushButtonState.Default;
                }

                else
                {
                    State = PushButtonState.Normal;
                }
            }
        }
        protected override void OnEnabledChanged(EventArgs e)
        {
            State = Enabled ? PushButtonState.Normal : PushButtonState.Disabled;

            base.OnEnabledChanged(e);
        }
		public override void UpDownBaseDrawButton (Graphics g, Rectangle bounds, bool top, PushButtonState state)
		{
			if (!RenderClientAreas) {
				base.UpDownBaseDrawButton (g, bounds, top, state);
				return;
			}
			VisualStyleElement element;
			if (top)
				switch (state) {
				case PushButtonState.Disabled:
					element = VisualStyleElement.Spin.Up.Disabled;
					break;
				case PushButtonState.Pressed:
					element = VisualStyleElement.Spin.Up.Pressed;
					break;
				case PushButtonState.Hot:
					element = VisualStyleElement.Spin.Up.Hot;
					break;
				default:
					element = VisualStyleElement.Spin.Up.Normal;
					break;
				}
			else
				switch (state) {
				case PushButtonState.Disabled:
					element = VisualStyleElement.Spin.Down.Disabled;
					break;
				case PushButtonState.Pressed:
					element = VisualStyleElement.Spin.Down.Pressed;
					break;
				case PushButtonState.Hot:
					element = VisualStyleElement.Spin.Down.Hot;
					break;
				default:
					element = VisualStyleElement.Spin.Down.Normal;
					break;
				}
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.UpDownBaseDrawButton (g, bounds, top, state);
				return;
			}
			new VisualStyleRenderer (element).DrawBackground (g, bounds);
		}
 /// <summary>
 /// Raises the <see cref="M:System.Windows.Forms.Control.OnMouseEnter(System.EventArgs)"/> event.
 /// </summary>
 /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
 protected override void OnMouseEnter(EventArgs e)
 {
     ButtonState = PushButtonState.Hot;
     Invalidate();
     base.OnMouseEnter(e);
 }
        protected override void OnEnabledChanged(EventArgs e)
        {
            if (Enabled)
                State = PushButtonState.Normal;
            else
                State = PushButtonState.Disabled;

            base.OnEnabledChanged(e);
        }
 public virtual void DrawArrow(Graphics surface, DropDownButtonRenderingArgs args, PushButtonState state)
 {
     surface.SmoothingMode = SmoothingMode.HighQuality;
     surface.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
     surface.PixelOffsetMode = PixelOffsetMode.HighQuality;
     surface.InterpolationMode = InterpolationMode.HighQualityBicubic;
     surface.CompositingQuality = CompositingQuality.HighQuality;
     PointF center = new PointF(Convert.ToSingle(args.Bounds.Width / 2) + args.Bounds.X, Convert.ToSingle(args.Bounds.Height / 2) + args.Bounds.Y);
     PointF[] pts = new PointF[] { new PointF(center.X - 3, center.Y), new PointF(center.X + 2, center.Y), new PointF(center.X, center.Y + 3) };
     if (state == PushButtonState.Disabled)
     {
         surface.FillPolygon(Brushes.DarkGray, pts);
         surface.DrawPolygon(Pens.LightGray, pts);
     }
     else
     {
         surface.FillPolygon(Brushes.Black, pts);
         surface.DrawPolygon(Pens.DimGray, pts);
     }
 }
        protected override void OnMouseEnter(EventArgs e)
        {
            if (!showSplit)
            {
                base.OnMouseEnter(e);
                return;
            }

            isMouseEntered = true;

            if (!State.Equals(PushButtonState.Pressed) && !State.Equals(PushButtonState.Disabled))
            {
                State = PushButtonState.Hot;
            }
               
        }
Example #44
0
        /// <summary>
        /// Draws a push button in the specified state, on the specified graphics 
        /// surface, and within the specified bounds
        /// </summary>
        /// <param name="g">The Graphics to draw on</param>
        /// <param name="buttonRect">The Rectangle that represents the dimensions 
        /// of the button</param>
        /// <param name="clipRect">The Rectangle that represents the clipping area</param>
        /// <param name="state">A PushButtonState value that specifies the 
        /// state to draw the button in</param>
        /// <param name="flatStyle">If true, then the button is drawn in flat style, but only if VisualStyles are not being used.</param>
        public static void DrawButton(Graphics g, Rectangle buttonRect, Rectangle clipRect, PushButtonState state, bool flatStyle)
        {
            if (g == null || buttonRect.Width <= 0 || buttonRect.Height <= 0 || clipRect.Width <= 0 || clipRect.Height <= 0)
            {
                return;
            }

            if (ThemeManager.VisualStylesEnabled)
            {
                //ThemeManager.DrawThemeBackground(g, ThemeClasses.Button, (int) ButtonParts.PushButton, (int) state, buttonRect, clipRect);
                VisualStyleRenderer renderer;
                switch (state)
                {
                    case PushButtonState.Disabled:
                        renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Disabled);
                        break;
                    case PushButtonState.Hot:
                        renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);
                        break;
                    case PushButtonState.Normal:
                        renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
                        break;
                    case PushButtonState.Pressed:
                        renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Pressed);
                        break;
                    default:
                        renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Default);
                        break;
                }
                renderer.DrawBackground(g, buttonRect, clipRect);
            }
            else
            {
                ButtonState newState = ThemeManager.ConvertPushButtonStateToButtonState(state);
                if (flatStyle)
                    newState = newState | ButtonState.Flat;
                ControlPaint.DrawButton(g, buttonRect, newState);
            }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!showSplit)
            {
                base.OnMouseDown(e);
                return;
            }

            //handle ContextMenu re-clicking the drop-down region to close the menu
            if (m_SplitMenuStrip != null && e.Button == MouseButtons.Left && !isMouseEntered)
                skipNextOpen = true;

            if (dropDownRectangle.Contains(e.Location) && !isSplitMenuVisible && e.Button == MouseButtons.Left)
            {
                ShowContextMenuStrip();
            }
            else
            {
                State = PushButtonState.Pressed;
            }
        }
Example #46
0
        protected override void DrawScrollButton(Graphics dc, Rectangle bounds, Rectangle clippingArea, ScrollButton button, PushButtonState state)
        {
            if (!ThemeVisualStyles.RenderClientAreas)
            {
                base.DrawScrollButton(dc, bounds, clippingArea, button, state);
                return;
            }
            VisualStyleElement element;

            if (button == ScrollButton.Left)
            {
                switch (state)
                {
                case PushButtonState.Hot:
                    element = VisualStyleElement.Spin.DownHorizontal.Hot;
                    break;

                case PushButtonState.Pressed:
                    element = VisualStyleElement.Spin.DownHorizontal.Pressed;
                    break;

                default:
                    element = VisualStyleElement.Spin.DownHorizontal.Normal;
                    break;
                }
            }
            else
            {
                switch (state)
                {
                case PushButtonState.Hot:
                    element = VisualStyleElement.Spin.UpHorizontal.Hot;
                    break;

                case PushButtonState.Pressed:
                    element = VisualStyleElement.Spin.UpHorizontal.Pressed;
                    break;

                default:
                    element = VisualStyleElement.Spin.UpHorizontal.Normal;
                    break;
                }
            }
            if (!VisualStyleRenderer.IsElementDefined(element))
            {
                if (button == ScrollButton.Left)
                {
                    switch (state)
                    {
                    case PushButtonState.Hot:
                        element = VisualStyleElement.ScrollBar.ArrowButton.LeftHot;
                        break;

                    case PushButtonState.Pressed:
                        element = VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
                        break;

                    default:
                        element = VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
                        break;
                    }
                }
                else
                {
                    switch (state)
                    {
                    case PushButtonState.Hot:
                        element = VisualStyleElement.ScrollBar.ArrowButton.RightHot;
                        break;

                    case PushButtonState.Pressed:
                        element = VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
                        break;

                    default:
                        element = VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
                        break;
                    }
                }
                if (!VisualStyleRenderer.IsElementDefined(element))
                {
                    base.DrawScrollButton(dc, bounds, clippingArea, button, state);
                    return;
                }
            }
            new VisualStyleRenderer(element).DrawBackground(dc, bounds, clippingArea);
        }
 private void SetButtonDrawState()
 {
     if (Bounds.Contains(Parent.PointToClient(Cursor.Position)))
     {
         State = PushButtonState.Hot;
     }
     else if (Focused)
     {
         State = PushButtonState.Default;
     }
     else if (!Enabled)
     {
         State = PushButtonState.Disabled;
     }
     else
     {
         State = PushButtonState.Normal;
     }
 }
Example #48
0
 protected override void OnMouseLeave(int rowIndex)
 {
     base.OnMouseLeave(rowIndex);
     this.m_curBtnState = PushButtonState.Normal;
     this.DataGridView.InvalidateCell(this);
 }
        public virtual void DrawButton(Graphics surface, DropDownButtonRenderingArgs args, PushButtonState state)
        {
            surface.SmoothingMode = SmoothingMode.HighQuality;
            surface.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            surface.PixelOffsetMode = PixelOffsetMode.HighQuality;
            surface.InterpolationMode = InterpolationMode.HighQualityBicubic;
            surface.CompositingQuality = CompositingQuality.HighQuality;
            if (args.Image == null)
            { ButtonRenderer.DrawButton(surface, args.Bounds, args.Focused, state); }
            else
            { ButtonRenderer.DrawButton(surface, args.Bounds, args.Image, args.ImageBounds, args.Focused, state); }

            if (state == PushButtonState.Disabled)
            {
                TextRenderer.DrawText(surface, args.Text, args.Font, args.Bounds, SystemColors.GrayText, args.BackColor, args.TextFormatFlags);
            }
            else
            {
                TextRenderer.DrawText(surface, args.Text, args.Font, args.Bounds, args.ForeColor, args.BackColor, args.TextFormatFlags);
            }
        }
Example #50
0
        protected override void OnPaintButton(Graphics g, PushButtonState state, bool drawFocusCues, bool drawKeyboardCues)
        {
            PushButtonState newState;

            if (this.forcedPushed)
            {
                newState = PushButtonState.Pressed;
            }
            else
            {
                newState = state;
            }

            OnPaintButtonImpl(g, newState, drawFocusCues, drawKeyboardCues);
        }
Example #51
0
 public static void DrawButton(Graphics g, Rectangle bounds, PushButtonState state)
 {
     DrawButton(g, bounds, String.Empty, null, TextFormatFlags.Default, null, Rectangle.Empty, false, state);
 }
Example #52
0
        private void OnPaintButtonImpl(Graphics g, PushButtonState state, bool drawFocusCues, bool drawKeyboardCues)
        {
            Color backColor;
            Color outlineColor;
            Color arrowFillColor;
            Color arrowOutlineColor;

            switch (state)
            {
                case PushButtonState.Disabled:
                    backColor = Color.Transparent;
                    outlineColor = BackColor;
                    arrowFillColor = Color.Gray;
                    arrowOutlineColor = Color.Black;
                    break;

                case PushButtonState.Hot:
                    backColor = Color.FromArgb(64, SystemColors.HotTrack);
                    outlineColor = backColor;
                    arrowFillColor = Color.Blue;
                    arrowOutlineColor = Color.White;
                    break;

                case PushButtonState.Default:
                case PushButtonState.Normal:
                    backColor = Color.Transparent;
                    outlineColor = Color.Transparent;
                    arrowFillColor = Color.Black;
                    arrowOutlineColor = Color.White;
                    break;

                case PushButtonState.Pressed:
                    backColor = Color.FromArgb(192, SystemColors.Highlight);
                    outlineColor = Color.FromArgb(192, SystemColors.Highlight);
                    arrowFillColor = Color.Blue;
                    arrowOutlineColor = Color.White;
                    break;

                default:
                    throw new InvalidEnumArgumentException("buttonState");
            }

            // Draw parent background
            IPaintBackground asIpb = Parent as IPaintBackground;

            if (!this.drawWithGradient || asIpb == null)
            {
                if (asIpb != null)
                {
                    Rectangle screenRect = RectangleToScreen(ClientRectangle);
                    Rectangle parentRect = Parent.RectangleToClient(screenRect);

                    g.TranslateTransform(-Left, -Top, MatrixOrder.Append);
                    asIpb.PaintBackground(g, parentRect);
                    g.TranslateTransform(+Left, +Top, MatrixOrder.Append);
                }
                else
                {
                    using (SolidBrush backBrush = new SolidBrush(BackColor))
                    {
                        g.FillRectangle(backBrush, ClientRectangle);
                    }
                }
            }
            else
            {
                if (this.backBufferSurface != null &&
                    (this.backBufferSurface.Width != ClientSize.Width || this.backBufferSurface.Height != ClientSize.Height))
                {
                    this.backBuffer.Dispose();
                    this.backBuffer = null;

                    this.backBufferSurface.Dispose();
                    this.backBufferSurface = null;
                }

                if (this.backBufferSurface == null)
                {
                    this.backBufferSurface = new Surface(ClientSize.Width, ClientSize.Height);
                    this.backBuffer = new RenderArgs(this.backBufferSurface);
                }

                Rectangle screenRect = RectangleToScreen(ClientRectangle);
                Rectangle parentRect = Parent.RectangleToClient(screenRect);

                using (Graphics bg = Graphics.FromImage(this.backBuffer.Bitmap))
                {
                    bg.TranslateTransform(-Left, -Top, MatrixOrder.Append);
                    asIpb.PaintBackground(bg, parentRect);
                }

                BitmapData bitmapData = this.backBuffer.Bitmap.LockBits(
                    new Rectangle(0, 0, this.backBuffer.Bitmap.Width, this.backBuffer.Bitmap.Height), 
                    ImageLockMode.ReadWrite, 
                    PixelFormat.Format32bppArgb);

                int startAlpha;
                int finishAlpha;

                if (this.arrowDirection == ArrowDirection.Left || this.arrowDirection == ArrowDirection.Up)
                {
                    startAlpha = 255;
                    finishAlpha = 0;
                }
                else if (this.arrowDirection == ArrowDirection.Right || this.ArrowDirection == ArrowDirection.Down)
                {
                    startAlpha = 0;
                    finishAlpha = 255;
                }
                else
                {
                    throw new InvalidEnumArgumentException("this.arrowDirection");
                }

                unsafe
                {
                    if (this.arrowDirection == ArrowDirection.Left || this.arrowDirection == ArrowDirection.Right)
                    {
                        for (int x = 0; x < this.backBuffer.Bitmap.Width; ++x)
                        {
                            float lerp = (float)x / (float)(this.backBuffer.Bitmap.Width - 1);

                            if (this.arrowDirection == ArrowDirection.Left)
                            {
                                lerp = 1.0f - (float)Math.Cos(lerp * (Math.PI / 2.0));
                            }
                            else
                            {
                                lerp = (float)Math.Sin(lerp * (Math.PI / 2.0));
                            }

                            byte alpha = (byte)(startAlpha + ((int)(lerp * (finishAlpha - startAlpha))));
                            byte* pb = (byte*)bitmapData.Scan0.ToPointer() + (x * 4) + 3; // *4 because 4-bytes per pixel, +3 to get to alpha channel

                            for (int y = 0; y < this.backBuffer.Bitmap.Height; ++y)
                            {
                                *pb = alpha;
                                pb += bitmapData.Stride;
                            }
                        }
                    }
                    else if (this.arrowDirection == ArrowDirection.Up || this.arrowDirection == ArrowDirection.Down)
                    {
                        for (int y = 0; y < this.backBuffer.Bitmap.Height; ++y)
                        {
                            float lerp = (float)y / (float)(this.backBuffer.Bitmap.Height - 1);
                            lerp = 1.0f - (float)Math.Cos(lerp * (Math.PI / 2.0));

                            byte alpha = (byte)(startAlpha + ((int)(lerp * (finishAlpha - startAlpha))));
                            byte* pb = (byte*)bitmapData.Scan0.ToPointer() + (y * bitmapData.Stride) + 3; // *Stride for access to start of row, +3 to get to alpha channel

                            for (int x = 0; x < this.backBuffer.Bitmap.Width; ++x)
                            {
                                *pb = alpha;
                                pb += 4; // 4 for byte size of pixel
                            }
                        }
                    }
                }

                this.backBuffer.Bitmap.UnlockBits(bitmapData);
                bitmapData = null;

                g.DrawImage(this.backBuffer.Bitmap, new Point(0, 0));
            }

            using (SolidBrush fillBrush = new SolidBrush(backColor))
            {
                g.FillRectangle(fillBrush, ClientRectangle);
            }

            // Draw outline
            using (Pen outlinePen = new Pen(outlineColor))
            {
                g.DrawRectangle(outlinePen, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1));
            }

            // Draw button
            g.SmoothingMode = SmoothingMode.AntiAlias;

            const int arrowInset = 3;
            int arrowSize = Math.Min(ClientSize.Width - arrowInset * 2, ClientSize.Height - arrowInset * 2) - 1;

            PointF a;
            PointF b;
            PointF c;

            switch (this.arrowDirection)
            {
                case ArrowDirection.Left:
                    a = new PointF(arrowInset, ClientSize.Height / 2);
                    b = new PointF(ClientSize.Width - arrowInset, (ClientSize.Height - arrowSize) / 2);
                    c = new PointF(ClientSize.Width - arrowInset, (ClientSize.Height + arrowSize) / 2);
                    break;

                case ArrowDirection.Right:
                    a = new PointF(ClientSize.Width - arrowInset, ClientSize.Height / 2);
                    b = new PointF(arrowInset, (ClientSize.Height - arrowSize) / 2);
                    c = new PointF(arrowInset, (ClientSize.Height + arrowSize) / 2);
                    break;

                case ArrowDirection.Up:
                    a = new PointF(ClientSize.Width / 2, (ClientSize.Height - arrowSize) / 2);
                    b = new PointF((ClientSize.Width - arrowSize) / 2, (ClientSize.Height + arrowSize) / 2);
                    c = new PointF((ClientSize.Width + arrowSize) / 2, (ClientSize.Height + arrowSize) / 2);
                    break;

                case ArrowDirection.Down:
                    a = new PointF(ClientSize.Width / 2, (ClientSize.Height + arrowSize) / 2);
                    b = new PointF((ClientSize.Width - arrowSize) / 2, (ClientSize.Height - arrowSize) / 2);
                    c = new PointF((ClientSize.Width + arrowSize) / 2, (ClientSize.Height - arrowSize) / 2);
                    break;

                default:
                    throw new InvalidEnumArgumentException("this.arrowDirection");
            }

            // SPIKE in order to get this rendering correctly right away
            if (this.arrowDirection == ArrowDirection.Down)
            {
                SmoothingMode oldSM = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.None;

                float top = b.Y - 2;
                float left = b.X;
                float right = c.X;
                int squareCount = (int)((right - left) / 3);

                Brush outlineBrush = new SolidBrush(arrowOutlineColor);
                Brush interiorBrush = new SolidBrush(arrowFillColor);

                g.FillRectangle(interiorBrush, left, top, right - left + 1, 3);

                ++left;
                while (left < right)
                {
                    RectangleF rect = new RectangleF(left, top + 1, 1, 1);
                    g.FillRectangle(outlineBrush, rect);
                    left += 2;
                }

                outlineBrush.Dispose();
                outlineBrush = null;

                interiorBrush.Dispose();
                interiorBrush = null;

                a.Y += 2;
                b.Y += 2;
                c.Y += 2;

                g.SmoothingMode = oldSM;
            }

            if (this.reverseArrowColors)
            {
                Utility.Swap(ref arrowFillColor, ref arrowOutlineColor);
            }

            using (Brush buttonBrush = new SolidBrush(arrowFillColor))
            {
                g.FillPolygon(buttonBrush, new PointF[] { a, b, c });
            }

            using (Pen buttonPen = new Pen(arrowOutlineColor, this.arrowOutlineWidth))
            {
                g.DrawPolygon(buttonPen, new PointF[] { a, b, c });
            }
        }
Example #53
0
 public static void DrawButton(Graphics g, Rectangle bounds, string buttonText, Font font, TextFormatFlags flags, bool focused, PushButtonState state)
 {
     DrawButton(g, bounds, buttonText, font, flags, null, Rectangle.Empty, focused, state);
 }
Example #54
0
 /// <summary>
 /// Raises the KeyUp event</summary>
 /// <param name="kevent">KeyEventArgs that contains the event data</param>
 protected override void OnKeyUp(KeyEventArgs kevent)
 {
     if (kevent.KeyCode.Equals(Keys.Space))
     {
         if (MouseButtons == MouseButtons.None)
         {
             MState = PushButtonState.Normal;
         }
     }
     base.OnKeyUp(kevent);
 }
Example #55
0
        private readonly int _buttonImageOffset; // The amount of offset or border around the image

        protected DataGridViewImageButtonCellExt()
        {
            _buttonState       = PushButtonState.Disabled;
            _buttonImageOffset = 3;
            LoadImages();
        }
Example #56
0
 /// <summary>
 /// Raises the LostFocus event</summary>
 /// <param name="e">EventArgs that contains the event data</param>
 protected override void OnLostFocus(EventArgs e)
 {
     if (!m_showSplit)
     {
         base.OnLostFocus(e);
         return;
     }
     if (!MState.Equals(PushButtonState.Pressed) && !MState.Equals(PushButtonState.Disabled))
     {
         MState = PushButtonState.Normal;
     }
 }
Example #57
0
        /// <summary>
        ///  Renders a Button control.
        /// </summary>
        public static void DrawButton(Graphics g, Rectangle bounds, string buttonText, Font font, TextFormatFlags flags, bool focused, PushButtonState state)
        {
            Rectangle contentBounds;
            Color     textColor;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                visualStyleRenderer.DrawBackground(g, bounds);
                contentBounds = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds);
                textColor     = visualStyleRenderer.GetColor(ColorProperty.TextColor);
            }
            else
            {
                ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
                contentBounds = Rectangle.Inflate(bounds, -3, -3);
                textColor     = SystemColors.ControlText;
            }

            TextRenderer.DrawText(g, buttonText, font, contentBounds, textColor, flags);

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, contentBounds);
            }
        }
Example #58
0
        /// <summary>
        /// Raises the MouseDown event</summary>
        /// <param name="e">MouseEventArgs that contains the event data</param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!m_showSplit)
            {
                base.OnMouseDown(e);
                return;
            }

            if (m_dropDownRectangle.Contains(e.Location))
            {
                ShowContextMenuStrip();
            }
            else
            {
                MState = PushButtonState.Pressed;
            }
        }
 /// <summary>
 /// Raises the <see cref="E:System.Windows.Forms.Control.MouseLeave"/> event.
 /// </summary>
 /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
 protected override void OnMouseLeave(EventArgs e)
 {
     ButtonState = Enabled ? PushButtonState.Normal : PushButtonState.Disabled;
     Invalidate();
     base.OnMouseLeave(e);
 }
        protected override void OnKeyUp(KeyEventArgs kevent)
        {
            if (kevent.KeyCode.Equals(Keys.Space))
            {
                if (Control.MouseButtons == MouseButtons.None)
                {
                    State = PushButtonState.Normal;
                }
            }
            else if (kevent.KeyCode.Equals(Keys.Apps))
            {
                if (Control.MouseButtons == MouseButtons.None && !isSplitMenuVisible)
                {
                    ShowContextMenuStrip();
                }
            }

            base.OnKeyUp(kevent);
        }