C# AutoSize 标签问题
在我的程序中,我有用户可以随意添加的标签控件,标签也可以绑定到数据源。我将 AutoSize 属性添加到我设计的属性网格中,并且可以选择随意打开和关闭它。我遇到的问题是,如果属性网格中的 AutoSize 标志设置为 true,它将 AutoSize 为当前单元格内容,这是正确的,但如果我在数据源中向前移动一条记录,并且文本比标签长标签将不会再次调整大小。我做错了什么还是 AutoSize 的工作方式如此?
还有人知道是否可以在运行时使对齐线对齐控件吗?
谢谢。
In my program I have label controls which users can add at will, the labels can be bound to data source too. I added the AutoSize property to a property grid I designed and there is the option to turn this on and off at will. The problem I am running into is that if the AutoSize flag is set to true in the property grid it will AutoSize to the current cell contents which is correct but if I move ahead one record in my data source and the text is longer then the label the label will not resize again. Am I doing something wrong or this the way AutoSize works?
Also does anyone know if it possible to make snap lines available at run time to align controls?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您的问题,您正在创建一个自定义组件“标签”,问题是当其文本更改时不会调整其大小。看一下 Control.OnTextChanged 方法,你可以把你的尺寸调整逻辑放在那里。像这样的:
至于对齐线,这些被设计器淹没,在运行时您可以通过覆盖表单或父控件的 OnPaint 方法自己绘制它们
if I'm understanding your question correctly you're creating a custom component "label" and the problem is that is doesn't adjust its size when its text is changed. Take a look at the Control.OnTextChanged method, you can put your size adjusting logic there. Smth like this:
as for snap lines, those are drown by designer, in run time you can draw them yourself by overriding your form or parent control OnPaint method