1 Replies - 6938 Views - Last Post: 20 September 2012 - 10:14 PM Rate Topic: -----

#1 mason2008   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-September 12

how to refresh a component through its container

Posted 20 September 2012 - 07:23 PM

I build some components to draw a column chart, put them in a control and draw them in the control's OnPaint() by passing the control's graphics object to them.

My question is how to refresh the column chart? what I am not sure is which one should I pass the data to, the component or the control? Do I need to redraw the whole control every time I redraw the component?
Is This A Good Question/Topic? 0
  • +

Replies To: how to refresh a component through its container

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6166
  • View blog
  • Posts: 21,264
  • Joined: 05-May 12

Re: how to refresh a component through its container

Posted 20 September 2012 - 10:14 PM

You obviously have to repaint the control's client area when you get the OnPaint() callback, so that is one part of the redraw puzzle. If you look closely at the event object that you get, you can find out what region needs to be repainted, so you can be potentially save time by just redrawing the part that needs repainting, and not the entire client area.

The other part of the puzzle is repainting when the data for the chart changes. One technique is to simply invalidate the entire client rectangle for the control and wait for the OnPaint() callback to be invoked. The alternative is to proactively repaint the client area when the data changes. Personally, I recommend waiting for the callback.

As for who holds the data: the control or the component? It really depends on your design. Are the components swappable like in a Strategy pattern? In that case, it may make more sense for the control to hold the data and just pass it to the component at paint time. If that isn't the case, then in may be prudent to have the component hold the data because you want to have a good separation of concerns and if the control doesn't need to know anything about the data, then don't.

You should post your code. Others may have more input if they have code to point to and discuss.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1