using System.Drawing;
|
using System.Windows.Forms;
|
|
namespace HalconTools
|
{
|
public class StyleSetTools
|
{
|
public void SetCellColor(DataGridView dgv, int rowIndex, int columnIndex, Color col, Color back)
|
{
|
DataGridViewCellStyle style = new DataGridViewCellStyle();
|
style.ForeColor = col;
|
style.SelectionForeColor = col;
|
style.BackColor = back;
|
style.SelectionBackColor = back;
|
style.Font = new Font("Arial", 10f, FontStyle.Bold);
|
dgv.Rows[rowIndex].Cells[columnIndex].Style = style;
|
}
|
|
public void SetColumnColor(DataGridView dgv, int colIndex, Color col, Color back)
|
{
|
DataGridViewCellStyle style = new DataGridViewCellStyle();
|
style.ForeColor = col;
|
style.SelectionForeColor = col;
|
style.BackColor = back;
|
style.SelectionBackColor = back;
|
style.Font = new Font("Arial", 10f, FontStyle.Bold);
|
dgv.Columns[colIndex].DefaultCellStyle = style;
|
}
|
|
public void SetColumnWidth(DataGridView dgv, int colIndex, int width)
|
{
|
dgv.Columns[colIndex].Width = width;
|
}
|
|
public void SetDefaultView(DataGridView dgv, int width, int height, int x, int y)
|
{
|
dgv.GridColor = Color.BlueViolet;
|
dgv.BorderStyle = BorderStyle.Fixed3D;
|
dgv.CellBorderStyle = DataGridViewCellBorderStyle.Sunken;
|
dgv.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken;
|
dgv.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken;
|
dgv.DefaultCellStyle.BackColor = Color.White;
|
dgv.DefaultCellStyle.SelectionBackColor = Color.White;
|
dgv.DefaultCellStyle.SelectionForeColor = Color.Black;
|
dgv.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
dgv.AllowUserToAddRows = false;
|
dgv.AllowUserToDeleteRows = false;
|
dgv.AllowUserToOrderColumns = true;
|
dgv.AllowUserToResizeColumns = false;
|
dgv.AllowUserToResizeRows = false;
|
dgv.ReadOnly = true;
|
dgv.RowHeadersVisible = false;
|
dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
|
dgv.ScrollBars = ScrollBars.Vertical;
|
dgv.ShowEditingIcon = false;
|
dgv.BackgroundColor = SystemColors.Control;
|
dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
|
dgv.ColumnHeadersVisible = false;
|
dgv.MultiSelect = false;
|
dgv.AutoGenerateColumns = true;
|
dgv.Location = new Point(x, y);
|
dgv.Size = new Size(width, height);
|
}
|
|
public void SetRowColor(DataGridView dgv, int rowIndex, Color col, Color back)
|
{
|
DataGridViewCellStyle style = new DataGridViewCellStyle();
|
style.ForeColor = col;
|
style.SelectionForeColor = col;
|
style.BackColor = back;
|
style.SelectionBackColor = back;
|
style.Font = new Font("Arial", 10f, FontStyle.Bold);
|
dgv.Rows[rowIndex].DefaultCellStyle = style;
|
}
|
}
|
}
|