Esempio n. 1
0
        public override void OnPaint(object sender, RibbonElementPaintEventArgs e)
        {
            if (Owner != null)
            {
                Owner.Renderer.OnRenderRibbonItem(new RibbonItemRenderEventArgs(Owner, e.Graphics, Bounds, this));

                if (Style == CheckBoxStyle.CheckBox)
                {
                    CheckBoxState CheckState = Checked == true ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal;
                    if (Selected)
                    {
                        CheckState += 1;
                    }

                    if (this.CheckBoxOrientation == CheckBoxOrientationEnum.Left)
                    {
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(_checkboxBounds.Left, _checkboxBounds.Top), CheckState);
                    }
                    else
                    {
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(_checkboxBounds.Left + spacing, _checkboxBounds.Top), CheckState);
                    }
                }
                else
                {
                    RadioButtonState RadioState = Checked == true ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal;
                    if (Selected)
                    {
                        RadioState += 1;
                    }
                    if (this.CheckBoxOrientation == CheckBoxOrientationEnum.Left)
                    {
                        RadioButtonRenderer.DrawRadioButton(e.Graphics, new Point(_checkboxBounds.Left, _checkboxBounds.Top), RadioState);
                    }
                    else
                    {
                        RadioButtonRenderer.DrawRadioButton(e.Graphics, new Point(_checkboxBounds.Left + spacing, _checkboxBounds.Top), RadioState);
                    }
                }

                if (LabelVisible)
                {
                    StringFormat f = new StringFormat();
                    if (_CheckBoxOrientation == CheckBoxOrientationEnum.Left)
                    {
                        f.Alignment = StringAlignment.Near;
                    }
                    else
                    {
                        f.Alignment = StringAlignment.Far;
                    }

                    f.LineAlignment = StringAlignment.Far; //Top
                    f.Trimming      = StringTrimming.None;
                    f.FormatFlags  |= StringFormatFlags.NoWrap;
                    Owner.Renderer.OnRenderRibbonItemText(new RibbonTextEventArgs(Owner, e.Graphics, _labelBounds, this, LabelBounds, Text, f));
                }
            }
        }
Esempio n. 2
0
        // Main paiting method
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            int maxItem = this.Items.Count - 1;

            if (e.Index < 0 || e.Index > maxItem)
            {
                // Erase all background if control has no items
                e.Graphics.FillRectangle(BackBrush, this.ClientRectangle);
                return;
            }

            int size = e.Font.Height; // button size depends on font height, not on item height

            // Calculate bounds for background, if last item paint up to bottom of control
            Rectangle backRect = e.Bounds;

            if (e.Index == maxItem)
            {
                backRect.Height = this.ClientRectangle.Top + this.ClientRectangle.Height - e.Bounds.Top;
            }
            e.Graphics.FillRectangle(BackBrush, backRect);

            // Determines text color/brush
            Brush textBrush;
            bool  isChecked = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            RadioButtonState state = isChecked ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal;

            if ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled)
            {
                textBrush = SystemBrushes.GrayText;
                state     = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled;
            }
            else if ((e.State & DrawItemState.Grayed) == DrawItemState.Grayed)
            {
                textBrush = SystemBrushes.GrayText;
                state     = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled;
            }
            else
            {
                textBrush = SystemBrushes.FromSystemColor(this.ForeColor);
            }

            // Determines bounds for text and radio button
            Size  glyphSize     = RadioButtonRenderer.GetGlyphSize(e.Graphics, state);
            Point glyphLocation = e.Bounds.Location;

            glyphLocation.Y += (e.Bounds.Height - glyphSize.Height) / 2;

            Rectangle bounds = new Rectangle(e.Bounds.X + glyphSize.Width, e.Bounds.Y, e.Bounds.Width - glyphSize.Width, e.Bounds.Height);

            // Draws the radio button
            RadioButtonRenderer.DrawRadioButton(e.Graphics, glyphLocation, state);

            // Draws the text
            if (!string.IsNullOrEmpty(DisplayMember)) // Bound Datatable? Then show the column written in Displaymember
            {
                e.Graphics.DrawString(((System.Data.DataRowView) this.Items[e.Index])[this.DisplayMember].ToString(),
                                      e.Font, textBrush, bounds, this.Align);
            }
            else
            {
                e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, textBrush, bounds, this.Align);
            }

            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
        }