Grid Graphics
Hi,
I'm trying to paint a cell as an indicator for a value. I have noticed that the grid updates are slow at times and this paint cell seems to be causing it. I am using a model that implements the INotifyPropertyChanged interface and the model is getting updated on an non gui thread. I have listed below my code for the cell painting, can you tell me if this is the performant way to do this or if there is another way I should be doing it.
Thanks,
Deepak
case "Sentiment":
e.Parts &= e.Parts ^ PaintPart.Background;
DrawBlock(e.Cell.VirtualBounds, e.Graphics, e.Font, marketDisplayModel.SentimentO,
Color.LightSteelBlue, Color.LightSalmon);
e.Handled = true;
break;
The DrawBlock method is listed below.
protected void DrawBlock(Rectangle orginalVirtualBounds, Graphics graphics, Font font, double percent, Color percentColor, Color remainingColor)
{
Rectangle startBoxRemaining;
SolidBrush brush = new SolidBrush(Color.Black);
string text = "" + (Math.Round(percent,2));
if (font == null)
font = new Font("Arial", 10);
float x = (graphics.MeasureString(text, font)).Width;
Rectangle virtualBounds = new Rectangle(orginalVirtualBounds.X + 1, orginalVirtualBounds.Y + 1, orginalVirtualBounds.Width - 1, orginalVirtualBounds.Height - 1);
using (Brush b = new SolidBrush(percentColor))
{
Rectangle r = new Rectangle(virtualBounds.X + 1, virtualBounds.Y + 1, (int)(virtualBounds.Width * percent) - 1, virtualBounds.Height - 2);
startBoxRemaining = new Rectangle(virtualBounds.X + r.Width + 2, virtualBounds.Y + 1, (int)(virtualBounds.Width * (1 - percent)), virtualBounds.Height - 2);
graphics.FillRectangle(b, r);
}
using (Brush b = new SolidBrush(remainingColor))
{
graphics.FillRectangle(b, startBoxRemaining);
}
graphics.DrawString(text, font,
brush,
virtualBounds.Width / 2 + virtualBounds.X - (x / 2),
virtualBounds.Y);
}
-
Is there a phone number I can call you at. I'm still unclear about the process, it might be helpful to talk. Thanks.
0 -
btw, if NotifyPropertyChanged updates come from the GUI thread, then the Grid doesn't create ITask objects. The call stack will be as follows:
GUI thread: YourObject.SomeProperty->FireNotification->IDataAccessor->Grid->Cell->Control.Invalidate(Rectangle)
GUI thread (some time later): WM_PAINT->Grid drawing routine-> OnPaintRow() ->OnPaintCell() callback
Best regards,
Dapfor
0 -
Unfortunately we don't provide phone support.
0 -
Ok, How often does the GUI thread service the queue of the IDispatcher, is it on a timer or does it dequeue as soon as an item is queued. Secondly, I am not very clear on why you said I wasn't right, Is it because I'm calling the Notify Events in the Dispatcher queue. Can you tell me what is wrong in my example code ?
0 -
The GuiDispatcher posts a window message when the first Dispatch() method is called. The Windows distributes this message immediatly. When GuiDispatcher gets the message, its internal queue can contain several ITasks. What is about your example - it is fully correct. You call object's properties in the GUI thread via created tasks. The same effect you can get, if you set the dispatcher in the constructor of the grid. In this case the properties can be called in the non-GUI thread and the grid will synchronize threads itself via provided dispatcher. So we think the code will be more clean.
Best regards,
Dapfor
0
Please sign in to leave a comment.
Comments
35 comments