xcd
2020-03-29 95d9d4a9d26323c51087a056c25f88180f1e3c45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
        }
    }
}