Click here to Skip to main content
15,885,952 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 82.6K   7.6K   110  
Docking windows container, extended listview, extended property editor.
using System.Drawing;
using System;
using System.ComponentModel;

namespace dwf.tool
{
    public class PCellStyle : IDisposable
    {
        [NonSerialized()]
        static FontConverter fc = new FontConverter();
        protected string font = "Tahoma 8";
        [NonSerialized()]
        protected Font _font = null;
        [NonSerialized()]
        protected Font _sfont = null;
        [NonSerialized()]
        protected StringFormat _format;
        [DefaultValue((int)0)]
        protected int round = 0;
        [DefaultValue(0.0)]
        protected double angle = 0.0;
        [DefaultValue(true)]
        protected bool alternate = true;
        protected CellStyleBrush backBrush = null;
        protected CellStyleBrush borderBrush = null;
        protected CellStyleBrush fontBrush = null;

        public PCellStyle()
        {
            _format = new StringFormat(StringFormatFlags.DisplayFormatControl | StringFormatFlags.LineLimit);
            _format.LineAlignment = StringAlignment.Center;
            //_format.Trimming = StringTrimming.None;
        }

        public bool Alternate
        {
            get { return this.alternate; }
            set { alternate = value; }
        }

        public double Angle
        {
            get { return this.angle; }
            set { angle = value; }
        }

        public StringFormat Format
        {
            get { return _format; }
            set { _format = value; }
        }

        public Font Font
        {
            get
            {
                if (_font == null)
                    _font = (Font)fc.ConvertFromInvariantString(font);
                return _font;
            }
            set
            {
                if (_font != value)
                {
                    _font = value;
                    font = fc.ConvertToInvariantString(_font);
                }
            }
        }

        public Font SFont
        {
            get { return _sfont; }
            set
            {
                _sfont = value;
            }
        }

        public int Round
        {
            get { return round; }
            set { round = value; }
        }

        public CellStyleBrush BackBrush
        {
            get
            {
                if (backBrush == null)
                    backBrush = new CellStyleBrush();
                return this.backBrush;
            }
            set
            {
                backBrush = value;
            }
        }

        public CellStyleBrush BorderBrush
        {
            get
            {
                if (borderBrush == null)
                    borderBrush = new CellStyleBrush();
                return this.borderBrush;
            }
            set
            {
                borderBrush = value;
            }
        }

        public CellStyleBrush FontBrush
        {
            get
            {
                if (fontBrush == null)
                {
                    fontBrush = new CellStyleBrush();
                    fontBrush.Color = SystemColors.ControlText;
                    fontBrush.SColor = SystemColors.ControlText;
                    fontBrush.HColor = SystemColors.ControlText;
                    fontBrush.PColor = SystemColors.ControlText;
                    fontBrush.AColor = SystemColors.ControlText;
                }
                return this.fontBrush;
            }
            set
            {
                fontBrush = value;
            }
        }

        public PCellStyle Clone()
        {
            PCellStyle lcs = new PCellStyle();
            if (backBrush != null)
                lcs.backBrush = (CellStyleBrush)backBrush.Clone();
            if (borderBrush != null)
                lcs.borderBrush = (CellStyleBrush)borderBrush.Clone();
            if (fontBrush != null)
                lcs.fontBrush = (CellStyleBrush)fontBrush.Clone();
            lcs.font = font;
            lcs.Format = (StringFormat)_format.Clone();
            lcs.Round = round;
            return lcs;
        }


        public void Dispose()
        {
            if (_sfont != null)
                _sfont.Dispose();
            if (_font != null)
                _font.Dispose();
            if (_format != null)
                _format.Dispose();
            if (fontBrush != null)
                fontBrush.Dispose();
            if (borderBrush != null)
                borderBrush.Dispose();
            if (backBrush != null)
                backBrush.Dispose();
        }

        public void SwapFont()
        {
            Font  f = _font;
            _font = _sfont;
            _sfont = f;
        }
    }
}

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