我是C#的初学者,我正在尝试在Windows窗体中设置DataGridView按钮的样式。
我不知道如何从按钮中删除边框或更改悬停颜色。 DataGridView设置中缺少常规按钮上的许多配置。
如何在DataGridView中实现完整的可编辑按钮?
答案 0 :(得分:0)
Datagridview的工作方式与普通按钮略有不同, 但是如果搜索属性中的子属性,您仍然可以在其中编辑多个内容。我们来看一下细节:
<强> DefaultCellStyle 强>
选择dataGridView后,转到属性&gt; RowTemplate。在那里,你会发现一个名为DefaultCellStyle
的东西。如果你按下右边的'...'。然后它会打开一个弹出窗口,允许你改变一些Cell的标准设计。
同样也可以应用于ColumnHeadersDefaultCellStyle
,这与DefaultCellStyle几乎相同。
<强>列强>
您也可以转到Columns
并添加新列。添加新列后,您还可以设置该列唯一的几个属性。您甚至可以将列中的所有单元格设置为按钮!
Datagridview通常具有自定义权限,但大多数都分为单元格和列集合。
在悬停时更改背景颜色
这并不像普通按钮那样容易,我进行了搜索并找到了这个解决方案:
在属性中,在闪电按钮上,您可以看到事件,您可以在那里双击'CellMouseMove'并添加它。 (最终将datagridview1
名称更改为与您的名称相同)
private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Blue;
}
然后双击'CellMouseLeave'事件,以便它可以恢复颜色。
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.White;
}
我希望这对你有所帮助。