Winforms:创建动态时间线控件
我需要创建一个看起来像这样的 winforms 控件:
目前,我正在考虑使用图片框/面板并覆盖 onpaint 事件并自己绘制所有内容。但不知何故,这种方法似乎不太正确。
我想知道也许有更简单的方法或者更好的解决方案? 你会如何制作这样的控件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,这才是正确的做法。尝试使用像 TableLayoutPanel 这样的东西不仅极其痛苦,而且还需要花费一秒钟或更长时间来绘制自己,这会导致严重的泥浆。这将需要一堆代码,但它不是硬代码。还有大量的 for 循环机会。
使用面板的 AutoScrollMinSize 获取滚动视图。使用 Graphics.TranslateTransform() 在 Paint 事件或 OnPaint 重写中传递 AutoScrollPosition。推荐后者,从Panel派生您自己的控件以保持代码分离。您可以在这里灵活地自定义外观,玩得开心。
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.
覆盖文字控件或从 CompositeControl 类继承,然后使用 HTML(表)和 Javascript 呈现它(而不是绘制它)可能会更容易。
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.