按钮TextImageRelation和TextAlign问题
当在我的项目中使用按钮时...它们公开了一个名为 TextImageRelation
的属性。这用于告诉控件将按钮图像放置在与文本相关的位置(我使用的是 ImageBeforeText 选项)。现在,我需要将文本居中对齐。
我希望看到的逻辑结果是:图像左对齐,按钮文本居中于图像和按钮右边框之间的空间。
但不是......文本与图像旁边对齐或对齐到中心但不考虑图像(不确定哪种情况)。
有办法改变这种行为吗?
When using a Button in my projects... they expose a property called TextImageRelation
. This is used to tell the control where to place the button image in relation with the text (I'm using the ImageBeforeText option). Now, I need to have the text aligned to the center.
The logic outcome I would spect is: an image aligned to the left and the button text centred in the space between the image and the right border of the button.
But not... the text is aligned next to the image OR aligned to center but not taking into account the image (not sure which case).
There is a way to change this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是你不能。布局由内部 ButtonBaseAdapter.CommonLayout() 方法确定,您不能覆盖它。
TextImageRelation = Overlay 根据 TextAlign 设置对齐文本。图像被忽略。
设置 TextImageRelation = ImageBeforeText 后,文本始终与图像右侧齐平对齐。间隙大小是固定的,3个像素。将文本向右移动的一种非常愚蠢但有效的方法是在文本前添加空格。但还不足以确保它居中。无论如何,您通常不会想要这样,按钮标题应该对齐。请注意,RightToLeft = Yes 为您提供了更多修改方法,但不是您想要的。
Unfortunately you can't. The layout is determined by the internal ButtonBaseAdapter.CommonLayout() method, you can't override it.
TextImageRelation = Overlay aligns the Text according to the TextAlign setting. The image is ignored.
Once you set TextImageRelation = ImageBeforeText then the Text is always aligned flush to the right of the image. The gap size is fixed, 3 pixels. A very silly but otherwise effective way to move the text to the right is to prefix the Text with spaces. Not good enough to ensure it is centered though. You'd normally wouldn't want this anyway, button captions ought to line up. Note that RightToLeft = Yes gives you more ways to tinker, just not what you are looking for.