שתף באמצעות


How can I change a DataGridView Fontsize in VB.Net at runtime

Question

Tuesday, June 13, 2006 4:10 PM

Is it possible to change a datagridview's fontsize at runtime? I have an application that is designed to run on a 1024 x 768 screen. However it will fit on a 800 x 600 screen if I reduce the fontsize. I have determined the screen resolution using the screen.primaryscreen.bounds.size.tostring function

I tried this:
Me.RatesDataGridView.Font.Size=8

but it is readonly.

 

All replies (3)

Tuesday, June 13, 2006 4:39 PM ✅Answered

I figured it out. I dropped an invisible label on the form named lblfont8

I then assigned the datagridview to use that font

me.ratesdatagridview.font=lblfont8.font

works great.


Tuesday, June 13, 2006 4:41 PM ✅Answered | 2 votes

Yeah you can also do it without the lable by saying me.ratesdatagridview.font = new Font("Arial", 10, FontStyle.Bold) (the enum might be wrong, can't remember).

Basically Font.Size is readonly, but Font isn't.


Friday, September 28, 2007 9:38 AM

thanks.

This code working correctly.