在Panel上动态添加Control后出现的问题
我已将视图列表添加到面板上,如下所示:
panelComponent.Controls.Add(viewListComponent);
一切正常。处理鼠标事件,重新绘制工作。但有一个问题:我无法动态移动它。如果我更改 control.Top
变量,它只会坐在那里而不移动。
就像控件粘在左上角一样。调整右侧和底部属性的大小效果很好!我是这样做的,没有动态添加,然后就没有问题了。
可能是什么原因造成的?我该如何解决?
I have added an View List onto a Panel like this:
panelComponent.Controls.Add(viewListComponent);
Everything works just fine. Mouse events are handled, repainting works. But one problem: I can't move it around dynamically. If I change the control.Top
variable, it just sits there without moving.
It's like the control is glued to the top left corner. Resizing the right and bottom properties works just fine! I did it without dynamically adding and then no problem.
What could be causing this, and how do I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两种可能的解释。第一个是 Dock 属性,将其停靠到顶部会使控件保持在容器的顶部,无论您为 Top 或 Location 属性分配什么。
另一种是值类型,Location属性是Point,一个结构体。此代码不会移动控件:
Two possible explanations. First is the Dock property, docking it to the top keeps the control at the top of the container, no matter what you assign to the Top or Location properties.
The other one is value types, the Location property is Point, a struct. This code will not move the control:
尝试使用
Location
属性:Try using the
Location
property: