Winforms: creating a dynamic timeline control
I need to create a winforms control what looks something like this:
Currently i'm considering taking a picturebox/panel and overriding onpaint event and drawing all the stuff myself. But开发者_开发技巧 somehow this approach doesn't seem right.I was wondering maybe there's an easier way out or perhaps a better solution? How would you make a control like this?
No, that is the right way to do it. Trying to use something like a TableLayoutPanel is not only excruciatingly painful, it also sucks serious mud taking a second or more to paint itself. It will take a bunch of code, but it isn't hard code. Plenty of for loop opportunities as well.
Get the scrolling view with panel's AutoScrollMinSize. Use Graphics.TranslateTransform() passing AutoScrollPosition in the Paint event or OnPaint override. The latter is recommended, derive your own control from Panel to keep the code separate. You have lots of flexibility here to customize the appearance, have fun.
The last time I did something like this I did the grid as a bitmap, loaded the image into a picture box, and drew directly on the image. The problem with using the paint event it's not persistent with minimizing etc unless you keep redrawing it.
It would probably be easier to override a literal control or inherit from the CompositeControl class and then render it with HTML (tables) and Javascript as opposed to drawing it.
精彩评论