c# 设置datagridview样式
//设置单元格自动宽 datagridview.DefaultCellStyle.WrapMode = DataGridViewTriState.True; datagridview.DefaultCellStyle.ForeColor = Color.White; datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader; //设置字体大小 System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); datagridview.RowsDefaultCellStyle = dataGridViewCellStyle1; datagridview.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; datagridview.AutoGenerateColumns = false; //设置列填充满区域 datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; datagridview.AllowUserToResizeColumns = false; datagridview.AllowUserToResizeRows = false; datagridview.BackImage = Image.FromFile(@"C:\Users\Administrator\Desktop\网格背景.jpg"); //设置cell背景透明 datagridview.ColumnHeadersDefaultCellStyle.BackColor = Color.Transparent; datagridview.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; datagridview.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; //加上这句前面的才起作用 datagridview.EnableHeadersVisualStyles = false; datagridview.DefaultCellStyle.BackColor = Color.Transparent; datagridview.DefaultCellStyle.ForeColor = Color.White; datagridview.SelectionMode = DataGridViewSelectionMode.FullRowSelect; datagridview.RowHeadersVisible = false; datagridview.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; datagridview.ReadOnly = true;