按钮TextImageRelation和TextAlign问题

发布于 2024-10-06 01:30:30 字数 248 浏览 2 评论 0原文

当在我的项目中使用按钮时...它们公开了一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕头说它不想醒 2024-10-13 01:30:30

不幸的是你不能。布局由内部 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文