Exemple #1
0
        /// <summary>Draws the control background, with a BackColor and the specified BackgroundImage.</summary>
        /// <param name="graphics">The graphics to draw on.</param>
        /// <param name="image">The background image to use for the background.</param>
        /// <param name="border">The shape settings.</param>
        /// <param name="color">The color.</param>
        /// <param name="enabled">The enabled.</param>
        /// <param name="mouseState">The mouse state.</param>
        /// <param name="rectangle">The coordinates of the rectangle to draw.</param>
        public static void DrawElement(Graphics graphics, Image image, Border border, ColorState color, bool enabled, MouseStates mouseState, Rectangle rectangle)
        {
            GraphicsPath _elementGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(rectangle, border);

            graphics.SetClip(_elementGraphicsPath);
            Color _colorState = ColorState.BackColorState(color, enabled, mouseState);

            graphics.FillRectangle(new SolidBrush(_colorState), rectangle);
            graphics.ResetClip();

            if (image != null)
            {
                graphics.SetClip(_elementGraphicsPath);
                graphics.DrawImage(image, rectangle);
                graphics.ResetClip();
            }

            VisualBorderRenderer.DrawBorderStyle(graphics, border, _elementGraphicsPath, mouseState);
        }
        /// <summary>Draw Sub Item (Cell) at location specified.</summary>
        /// <param name="graphicsSubItem">The graphics sub item.</param>
        /// <param name="rectSubItem">The rectangle sub item.</param>
        /// <param name="item">The item.</param>
        /// <param name="subItem">The sub item.</param>
        /// <param name="column">The column.</param>
        /// <param name="font">The font.</param>
        /// <param name="listView">The list View.</param>
        /// <param name="_newLiveControls">The _new Live Controls.</param>
        /// <param name="_liveControls">The _live Controls.</param>
        /// <param name="cellPaddingSize">The cell Padding Size.</param>
        /// <param name="checkBoxSize">The check Box Size.</param>
        public static void DrawSubItem(Graphics graphicsSubItem, Rectangle rectSubItem, VisualListViewItem item, VisualListViewSubItem subItem, int column, Font font, VisualListView listView, ArrayList _newLiveControls, ArrayList _liveControls, int cellPaddingSize, int checkBoxSize)
        {
            ConsoleEx.WriteDebug("ListViewRenderer::DrawSubItem Name: " + subItem.Name);

            Rectangle _controlRectangle = new Rectangle(rectSubItem.X, rectSubItem.Y, rectSubItem.Width, rectSubItem.Height);

            if ((subItem.EmbeddedControl != null) && !subItem.ForceText)
            {
                Control _control = subItem.EmbeddedControl;

                if (_control.Parent != listView)
                {
                    _control.Parent = listView;
                }

                // Update the control BackColor to the current list view BackColorState.
                if (_control is VisualControlBase visualControlBase)
                {
                    visualControlBase.BackColor = ColorState.BackColorState(listView.BackColorState, listView.Enabled, listView.MouseState);
                }

                Rectangle _subItemRectangle = new Rectangle(_controlRectangle.X, _controlRectangle.Y + 1, _controlRectangle.Width, _controlRectangle.Height - 1);

                // Type _type = _control.GetType();
                PropertyInfo _propertyInfo = _control.GetType().GetProperty("PreferredHeight");
                if (_propertyInfo != null)
                {
                    var _preferredHeight = (int)_propertyInfo.GetValue(_control, null);

                    if ((_preferredHeight + (listView.CellPaddingSize * 2) > listView.ItemHeight) && listView.AutoHeight)
                    {
                        listView.ItemHeight = _preferredHeight + (listView.CellPaddingSize * 2);
                    }

                    _subItemRectangle.Y = _controlRectangle.Y + ((_controlRectangle.Height - _preferredHeight) / 2);
                }

                _newLiveControls.Add(_control);
                if (_liveControls.Contains(_control))
                {
                    _liveControls.Remove(_control);
                }

                if (_control.Bounds.ToString() != _subItemRectangle.ToString())
                {
                    // Forces to invalidate.
                    _control.Bounds = _subItemRectangle;
                }

                if (_control.Visible != true)
                {
                    _control.Visible = true;
                }
            }
            else
            {
                // If the sub item color is not the same as the back color fo the control, AND the item is not selected, then color this sub item background.
                if ((subItem.BackColor.ToArgb() != listView.BackColor.ToArgb()) && !item.Selected && (subItem.BackColor != Color.White))
                {
                    using (SolidBrush _backColorBrush = new SolidBrush(subItem.BackColor))
                    {
                        graphicsSubItem.FillRectangle(_backColorBrush, rectSubItem);
                    }
                }

                // Check if we need checkboxes in this column.
                if (listView.Columns[column].CheckBoxes && subItem.CheckBox)
                {
                    rectSubItem = DrawCheckBox(graphicsSubItem, rectSubItem, subItem.Checked, checkBoxSize, listView);
                }

                // If there is an image, this routine will RETURN with exactly the space left for everything else after the image is drawn (or not drawn due to lack of space).
                if ((subItem.ImageIndex > -1) && (listView.ImageListItems != null) && (subItem.ImageIndex < listView.ImageListItems.Images.Count))
                {
                    rectSubItem = DrawCellGraphic(graphicsSubItem, rectSubItem, listView.ImageListItems.Images[subItem.ImageIndex], subItem.ImageAlignment, cellPaddingSize, listView);
                }

                // Deal with text color in a box on whether it is selected or not.
                Color textColor;
                if (item.Selected && listView.Selectable)
                {
                    textColor = listView.ItemSelectedTextColor;
                }
                else
                {
                    textColor = listView.ForeColor;
                    if (item.ForeColor.ToArgb() != listView.ForeColor.ToArgb())
                    {
                        textColor = item.ForeColor;
                    }
                    else if (subItem.ForeColor.ToArgb() != listView.ForeColor.ToArgb())
                    {
                        textColor = subItem.ForeColor;
                    }
                }

                DrawCellText(graphicsSubItem, rectSubItem, subItem.Text, font, listView.Columns[column].TextAlignment, textColor, item.Selected, listView);
                subItem.LastCellRectangle = rectSubItem; // important to ONLY catch the area where the text is drawn
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                if (GetStyle(ControlStyles.AllPaintingInWmPaint))
                {
                    OnPaintBackground(e);
                }

                MinimumSize = new Size(0, GetPreferredSize(Size.Empty).Height);

                Rectangle    _clientRectangle    = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
                GraphicsPath controlGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(_clientRectangle, _border);
                Color        backColorState      = ColorState.BackColorState(_backColor, Enabled, MouseState);

                e.Graphics.SetClip(controlGraphicsPath);
                VisualBackgroundRenderer.DrawBackground(e.Graphics, backColorState, BackgroundImage, MouseState, _clientRectangle, _border);
                VisualBorderRenderer.DrawBorderStyle(e.Graphics, _border, controlGraphicsPath, _mouseState);
                Rectangle arrowRectangle = new Rectangle(Width - _arrowSize.Width - 5, (Height / 2) - (_arrowSize.Height / 2), _arrowSize.Width, _arrowSize.Height);

                if (_image != null)
                {
                    e.Graphics.DrawImage(_image, new Rectangle(arrowRectangle.Left - _image.Width - 2, (Height / 2) - (_image.Height / 2), _imageSize.Width, _imageSize.Height));
                }

                VisualElementRenderer.RenderTriangle(e.Graphics, _arrowColor, _arrowDisabledColor, Enabled, _dropDownImage, arrowRectangle, Alignment.Vertical.Down);

                var       _check            = 0;
                Rectangle checkBoxRectangle = new Rectangle(3, (Height / 2) - 6, 12, 12);

                if (ShowCheckBox)
                {
                    _check = 15;

                    if (Checked)
                    {
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxRectangle.Location, CheckBoxState.CheckedNormal);
                    }
                    else
                    {
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxRectangle.Location, CheckBoxState.UncheckedNormal);
                    }
                }

                Size textSize = TextManager.MeasureText(Text, Font);

                Rectangle textBoxRectangle = new Rectangle(2 + _check, (Height / 2) - (textSize.Height / 2), textSize.Width, textSize.Height);
                TextRenderer.DrawText(e.Graphics, Text, Font, textBoxRectangle, ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);

                if (_showFocus && _focused)
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
                }

                e.Graphics.ResetClip();
            }
            catch
            {
                Invalidate();
            }
        }