Reputation: 4399
I have a BufferedGraphics
instance and I draw some graphs on it. I'd like to create a function called DrawLegends
that takes an instance of BufferedGraphics
and draws two strings as legend.
I can create a PointF
instance that points to (0, 0), but I want to put the legend on the bottom. How should I proceed with that? Can I do it with the BufferedGraphics
instance or would I also need the panel that I'm drawing on?
Upvotes: 1
Views: 185
Reputation: 48425
The important thing is that you need to know the dimensions (mainly height) of the drawing canvas (i.e. the panel). This will be used to ultimately calculate the position of the legend. So if you don't have the height information stored elsewhere then yes, you will have to use the panel to some degree
Upvotes: 1
Reputation: 18465
At the end of the day pretty much all objects which are drawn to the screen can be manually drawn on, as under the covers they have or expose a graphics object to paint onto when you feel like it.
So if you do your drawing on a graphics object or whatever you are currently using, then when you are done drawing just paint that graphics object onto whatever control you want to display it in. As you can treat graphics objects a bit like images. There is no reason why you cannot pass in the underlying controls graphics object you want to paint onto rather than making your own graphics object, but if you have a method which does:
void DrawGraph(string xLegend, string yLegend, IList<XYValues> values, Graphics graphics);
Then you can draw onto that graphics object with the data, call invalidate and your done.
Upvotes: 0