/// <summary>
        /// Applies style pallete to current <see cref="DataGridView"/> instance.
        /// </summary>
        /// <param name="pallete"><see cref="StylePallete"/> instance containing styling information.</param>
        public void ApplyStyle(DataGridViewPallete pallete)
        {
            // globals
            Control.Font          = pallete.Font;
            Control.BackColor     = pallete.BackColor;
            Control.ForeColor     = pallete.ForeColor;
            Control.BorderStyle   = BorderStyle.None;
            Control.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

            // column header
            Control.EnableHeadersVisualStyles   = false;
            Control.ColumnHeadersHeight         = pallete.HeaderHeight;
            Control.ColumnHeadersBorderStyle    = DataGridViewHeaderBorderStyle.Raised;
            Control.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;

            // rows
            Control.RowHeadersVisible       = false;
            Control.RowTemplate.Height      = pallete.RowHeight;
            Control.AutoSizeRowsMode        = DataGridViewAutoSizeRowsMode.None;
            Control.AutoSizeColumnsMode     = DataGridViewAutoSizeColumnsMode.None;
            Control.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

            // cell style
            Control.ColumnHeadersDefaultCellStyle = pallete.HeaderStyle;
            Control.DefaultCellStyle = pallete.CellStyle;
            Control.AlternatingRowsDefaultCellStyle = pallete.AlternatingRowCellStyle;
        }
Example #2
0
        public static void ApplyStyle(ref DataGridView control)
        {
            var pallete = new DataGridViewPallete();

            // globals
            control.Font          = pallete.Font;
            control.BackColor     = pallete.BackColor;
            control.ForeColor     = pallete.ForeColor;
            control.BorderStyle   = BorderStyle.None;
            control.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

            // column header
            control.EnableHeadersVisualStyles   = false;
            control.ColumnHeadersHeight         = pallete.HeaderHeight;
            control.ColumnHeadersBorderStyle    = DataGridViewHeaderBorderStyle.Raised;
            control.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;

            // rows
            control.RowHeadersVisible       = false;
            control.RowTemplate.Height      = pallete.RowHeight;
            control.AutoSizeRowsMode        = DataGridViewAutoSizeRowsMode.None;
            control.AutoSizeColumnsMode     = DataGridViewAutoSizeColumnsMode.None;
            control.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

            // cell style
            control.ColumnHeadersDefaultCellStyle = pallete.HeaderStyle;
            control.DefaultCellStyle = pallete.CellStyle;
            control.AlternatingRowsDefaultCellStyle = pallete.AlternatingRowCellStyle;

            // enable double buffer
            var type = typeof(Control);
            var prop = type.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);

            Debug.Assert(prop != null, "prop != null");
            prop.SetValue(control, true, null);
        }