How can I change the font in a DataGrid?
I am using:
dg开发者_StackOverflow.ForeColor = System.Drawing.Color.Black;
dg.BackColor = System.Drawing.Color.Beige;
to set the background and foreground color of a DataGrid
. How can I change the font to say Calibri or any others using the built-in methods.
If this is a web application, the DataGrid
class already provides a Font
property that you can set to
a font of your choosing. You can set it either from the designer or in your source code, just as you've set the BackColor
and ForeColor
properties.
However, as I mentioned in a comment, you should be very careful about setting controls to use a font that the user might not have installed on their computer. I recommend checking a list of web-safe fonts.
You can change the font with this code
dg.Font=new Font(string familyName,int size);
精彩评论