Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / Windows Forms

Controls Library: Extended ListView with Column Mapping

Rate me:
Please Sign up or sign in to vote.
4.86/5 (29 votes)
27 Mar 2014CPOL5 min read 83.2K   7.6K   110  
Docking windows container, extended listview, extended property editor.
using dwf.tool;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace dwf.gui
{
    public class GroupBoxItem : ILayoutMapItem, IComparable<ILayoutMapItem>, IComparable
    {
        private Control control;
        private int defaultHeight = 100;
        private bool expand = true;
        private bool fillW = false;
        private bool fillH = false;
        private GroupBoxMap map;
        private int col;
        private int row;
        private bool visible = true;
        private float w = 100;
        private float h = 100;
        PCellStyle style = new PCellStyle();
        private string name;
        public string Text;
        public Rectangle bound;
        public int HeaderHeight = 21;
        [NonSerialized()]
        protected RectangleF temp;

        public RectangleF Temp
        {
            get { return temp; }
            set { temp = value; }
        }


        public GroupBoxItem()
        {
            style.Round = 5;
            style.Font = new Font("Microsoft Sans Serif", 10F, FontStyle.Bold);
            style.BackBrush.Color = Color.LightGray;
            style.BackBrush.Type = CellStyleBrushType.Gradient;
            style.BorderBrush.Color = Color.Gray;
        }

        public Rectangle Bounds
        {
            get { return bound; }
            set
            {
                bound = value;

                if (!expand)
                    bound.Height = HeaderHeight + 5;

                if (control != null && control.Visible)
                {
                    var location = new Point(bound.X + 3, bound.Y + HeaderHeight + 3);
                    if (Control.Location != location)
                        Control.Location = location;
                    var size = new Size(bound.Width - 6, bound.Height - (HeaderHeight + 6));
                    if (Control.Size != size)
                        Control.Size = size;
                }
            }
        }

        public Control Control
        {
            get { return control; }
            set
            {
                if (control == value)
                    return;

                if (control != null)
                    control.SizeChanged -= ControlSizeChanged;

                control = value;
                control.AutoSize = true;
                if (map != null)
                    map.Controls.Add(control);

                if (control != null)
                    control.SizeChanged += ControlSizeChanged;
            }
        }

        private void ControlSizeChanged(object sender, EventArgs e)
        {
            //if (map != null && !Sizing)
            //     map.ResizeLayout();
        }

        public int DefaultHeight
        {
            get { return defaultHeight; }
            set { defaultHeight = value; }
        }

        [DefaultValue(true)]
        public bool Expand
        {
            get { return expand; }
            set
            {
                if (expand == value)
                    return;
                expand = value;
                if (control != null)
                    control.Visible = visible && expand;
            }
        }

        public void Paint(PaintEventArgs e)
        {
            Rectangle bound = Bounds;
            //base.OnPaint(e);
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            GraphContext gc = new GraphContext(e.Graphics);

            System.Drawing.Drawing2D.GraphicsPath path = GuiService.GetRoundedRect(bound, 8);
            gc.G.FillPath(Brushes.White, path);
            gc.G.DrawPath(Pens.Gray, path);
            path.Dispose();

            RectangleF rect = this.GetGliphBound(bound);
            RectangleF rectHeader = new RectangleF(bound.X + 6, bound.Y + 0, bound.Width - 12, this.HeaderHeight);
            RectangleF rectText = new RectangleF(bound.X + 10, bound.Y + 3, bound.Width - 40, rectHeader.Height - 5);

            GuiService.PaintCell(gc, Text, rectHeader, rectText, style, tool.CellDisplayState.Default);
            GuiService.PaintGliph(gc, rect, this.Expand ? 180 : 90, this.Expand ? Color.Black : Color.Empty);
        }

        public RectangleF GetGliphBound(Rectangle bound)
        {
            return new RectangleF(bound.Right - 30, bound.Y + 4, 16, 16);
        }


        public bool Visible
        {
            get { return visible; }
            set
            {
                if (visible == value)
                    return;
                visible = value;
                if (control != null)
                    control.Visible = visible && expand;
            }
        }

        public float Height
        {
            get { return h; }
            set { h = value; }
        }

        public float Width
        {
            get { return w; }
            set { w = value; }
        }

        public int Row
        {
            get { return row; }
            set
            {
                if (row == value)
                    return;
                row = value;
                if (map != null)
                    map.Sort();
            }
        }

        public int Col
        {
            get { return col; }
            set
            {
                if (col == value)
                    return;
                col = value;
                if (map != null)
                    map.Sort();
            }
        }

        public bool FillWidth
        {
            get { return fillW; }
            set { fillW = value; }
        }

        public bool FillHeight
        {
            get { return fillH; }
            set { fillH = value; }
        }

        public ILayoutMap Map
        {
            get { return map; }
            set
            {
                map = value as GroupBoxMap;
            }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public int CompareTo(ILayoutMapItem other)
        {
            return LayoutMapTool.Compare(this, other);
        }

        public int CompareTo(object obj)
        {
            return CompareTo(obj as ILayoutMapItem);
        }



    }


}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Kazakstan Kazakstan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions