C#winFrom⾃定义gridview样式制作好看的⼤屏显⽰队列
⾃定义队列可以根据某列⾃⾏给予固定的宽度、颜⾊显⽰等。废话不说直接贴代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Call_form
{
public partial class Form1 : Form
{
}
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None; //设置窗体为⽆边框样式
this.WindowState = FormWindowState.Maximized; //最⼤化窗体
data_grid_style();//DataGridView 的样式,当datagridview不存在数据则报错
}
#region 给datagridview赋值和设定样式
gridview不显示private void data_grid_style() {
//dataGridView1.RowHeadersVisible = false;//隐藏标题
//dataGridView1.ColumnHeadersVisible = false;//隐藏⾸列
//dataGridView1.Columns[0].Visible = true;
//dataGridView1.Columns[0].Visible = true;
dataGridView1.RowHeadersVisible = false;
//给相应的列固定宽度
dataGridView1.Columns[0].Width = 390;
dataGridView1.Columns[1].Width = 390;
dataGridView1.Columns[2].Width = 1100;
dataGridView1.RowTemplate.Height = 88;//设置⾏⾼
dataGridView1.Columns[1].DefaultCellStyle.ForeColor = System.Drawing.Color.HotPink;//定义指定列的格式
dataGridView1.Columns[1].DefaultCellStyle.SelectionForeColor = System.Drawing.Color.HotPink;
dataGridView1.Columns[0].DefaultCellStyle.ForeColor = System.Drawing.Color.HotPink;
dataGridView1.Columns[0].DefaultCellStyle.SelectionForeColor = System.Drawing.Color.HotPink;
//dataGridView1.Columns[0].DefaultCellStyle.Alignment= DataGridViewContentAlignment.MiddleCenter;//第⼀列居中
dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//第⼆列居中
//dataGridView1.ColumnHeadersDefaultCellStyle.Font= new System.Drawing.Font("微软雅⿊", 22F);
//dt.Clear();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle17 = new System.Windows.Forms.DataGridViewCellStyle();//定义奇数⾏的样式
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle18 = new System.Windows.Forms.DataGridViewCellStyle();//定义默认⾏的样式
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
dataGridViewCellStyle17.BackColor = System.Drawing.Color.LightCyan;
this.dataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle17;
this.dataGridView1.BackgroundColor = System.Drawing.Color.LightSkyBlue;
//this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle18.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
//dataGridViewCellStyle18.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(223)))), ((int)(((byte)(240)))));
dataGridViewCellStyle18.BackColor = System.Drawing.Color.White;
//dataGridViewCellStyle18.BackColor = System.Drawing.Color.LightSkyBlue;
dataGridViewCellStyle18.Font = new System.Drawing.Font("微软雅⿊", 22F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((by // dataGridViewCellStyle18.ForeColor = System.Drawing.Color.Navy;
dataGridViewCellStyle18.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle18.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle18;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
}
#endregion
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论