Row height and font
Hello.
I would like to get Row height and font.
Now i'm using like this.
Font TempFont = new Font(l_crFontName, l_nFontSize);
grid1.Headers[0].Appearance.RowFont = TempFont;
private void grid1_PaintRow(object sender, PaintRowEventArgs e)
{
e.Row.Height = (int)l_nFontSize + 6;
}
But Font and Row height are not good looking.
For larger Font Size ( font size = 22 ). The Text align is going to top, although i set to middle.
Thanks
-
Hello,
Did you see the Row.Adjust() method?
Regards,
Dapfor0 -
Why doesn't the row height adjust automatically to fit the specified row font?
0 -
This may not always be desirable. If the grid is constantly doing the adjustment and the programmer does not want to, he won’t able to keep the original size of rows.
But it is easy to implement using the grid’s API:
//Change the font:
header.Appearance.RowFont = ...;
//Adjust all visible rows
for(int i = 0; i < grid.Rows.Count; ++i)
{
Row row = grid.Rows[i];
row.Adjust();
}
//Adjust when a new row is added:
grid.RowAdded += delegate(object sender, GridRowEventArgs e)
{
e.Row.Adjust();
};Best regards,
Dapfor
0 -
I had originally done what you just suggested, but I also had to add the Adjust() call in the PaintRow event since the height went back to the original height when a row was updated.
0 -
Adjusting rows in grid.Paint events can have a negative impact on the performance. Each time when the grid paints cells, it will measure the optimal size. At which moment do you change the font’s weight - when the row is updated or painted? And how much rows do you have in the grid?
Regards,
Dapfor
0 -
I updated my code so that the Adjust() call is made in the RowUpdated event instead. Not sure why I didn't think of that before.
Thanks.
0 -
We think this will be more performant comparing to Grid.PaintRow event.
Dapfor
0 -
One final question. I'm using the grid to track stocks, which are updated many times per second. Is there anyway to set the row height just once, so that the Adjust() call doesn't have to be made on every single row update? The only time the row height needs to change is when the user changes the font for the rows.
0 -
Hello,
The response is in our previous post. When the user changes fonts call the following:
OnFontChanged(object sender, EventArgs e)
{
//Adjust all visible rows
for(int i = 0; i < grid.Rows.Count; ++i)
{
Row row = grid.Rows[i];
row.Adjust();
}
}Just some notes about Grid.RowUpdated and Grid.PaintRow:
May be you know that Windows paints the content in two steps:
1. It calls the method Control.Invalidate and cumulates a region
2. Then it sends a WM_PAINT message.
I.e it has an asynchronous rendering system. The Control.Invalidate may be called by many times, but the WM_PAINT message will come to redraw the content only once. The minimum interval between two WM_PAINT messages is 15 msec. If the system is overloaded, then WM_PAINT comes less often. Accordingly, the grid uses this feature for high-performance content displaying.
When you call Row.Update/Cell.Update or grid receives notification from INotifyPropertyChanged/IBindingList it implicitly calls the Control.Invalidate() method. Grid.RowUpdated callback is called at this stage. The second callback Grid.PaintXXX()is called when a WM_PAINT message arrives and only for rows displayed in visible bounds of the grid.
Therefore, stocks can be updated as often as needed, without an impact on the application performance.
Hope, this will help you,Dapfor
0 -
Hi,
I want to change the font and font size of the grid header and hierarchical grid header
I used the following code to change font and font size.
Font TempFont = new Font(l_crFontName, l_nFontSize);
grid1.Headers[0].Appearance.RowFont = TempFont;
grid1.Headers[0].Appearance.ColumnCaptionFont = TempFont;
grid1.Headers[0].InvalidateRows();
grid1.Headers[1].Appearance.RowFont = TempFont;
grid1.Headers[1].Appearance.ColumnCaptionFont = TempFont;
grid1.Headers[1].InvalidateRows();
Font size changing for headers [0] is ok. But headers[1] font size does not change as I want.
Can you suggest me the correct way to change the font size for hierarchical header?
Thanks in advance.
Wish everyone happy and successful in upcoming years !
Best Rgds0 -
Hello,
Happy new year and best wishes in 2013!
We didn't find any problem with font. Which version of the grid do you use and what behaviour do you expect?
Best regards,
Dapfor
0
Please sign in to leave a comment.
Comments
11 comments