在面板中滚动形状
我正在开发一个在面板上绘制形状的程序。我向面板添加了一个垂直滚动条,但是当滚动面板时,形状保持在原来的位置并且不滚动。如何使这些形状滚动?
我在绘制处理程序中使用此代码来更新这些形状:
e.Graphics.FillRectangle(Brushes.Red, selectedRect);
I'm working on a program which draws shapes on a panel. I added a vertical scroll bar to the panel but when scrolling the panel, the shapes stays where they are and don't scroll. How can I make these shapes scroll?
I'm using this code in the paint handler to update these shapes:
e.Graphics.FillRectangle(Brushes.Red, selectedRect);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
滚动时,您应该注意面板的实际滚动位置,并在再次绘制形状时考虑此偏移。
网上有这样的例子(不完全是你的情况,但可以帮助识别问题):
我也在SO中找到了这个: 使用自动滚动控制 Windows.Forms.Panel 内的位置
on scrolling you should take care of the actual scroll position of the panel and consider this offset when painting your shapes again.
there are examples like this online (not exactly your case but could help to identify the problem):
I have also found this here in SO: Control position inside Windows.Forms.Panel with autoscroll
不要将 VerticalScrollBar 添加到面板中。当您设置 AutoScrollMinSize 属性时,面板已经自行处理滚动:
Don't add a VerticalScrollBar to the panel. The Panel already handles scrolling itself when you set the
AutoScrollMinSize
property: