SoFunction
Updated on 2025-03-07

How to change the border color of DataGridView control in C#

DataGridView is one of the most important data controls in Visual Studio. It can be applied in most occasions, is powerful and flexible to use. This article will focus on the border color of DataGridView.

Bill Geici said, "I think there is no software on Apple phones that should be the first of Microsoft." This shows that Geici has strong confidence in the functions of Microsoft software. As for Jobs, Microsoft's software has no sense of art! What does this mean? Microsoft's stuff - ugly!

Gangmaster Qiao is worthy of being Gangmaster Qiao. He is really a big hit and hits the point! Yes, DataGridView by default is really ugly! Especially the black border, it is not ordinary ugly. So, as a programmer with a little "art pursuit", how should we improve it! Let’s look at the function below that sets the DataGridView border.

Copy the codeThe code is as follows:

private void dataGridView1_Paint(object sender, PaintEventArgs e)
{
    (, new Rectangle(0, 0, this.-1, this.-1));
}

You can see at a glance that this is the Paint event of DataGridView. Yes, we want to change the border color when the DataGridView is drawn. This function is also very easy to understand, which is to draw a border of a specified color on the border of the dataGridView. This way its borders will change color.

Have you learned it, smart?