我在C#Windows窗体表单上有一个按钮,想要显示图像和一些文本,并排,并以按钮为中心。 我尝试将图像左对齐,右边的文本对齐,我得到了这个(句点是空格):
| [IMAGE} .................文|
但我想要这个:
| ........ [IMAGE]文字........ |
我的代码如下所示:
btnChangeStatus.Text = "Change status to SUPPRESSED"; btnChangeStatus.TextAlign = ContentAlignment.MiddleRight; btnChangeStatus.Image=Image.FromFile(@"J:\nomail.gif"); btnChangeStatus.ImageAlign = ContentAlignment.MiddleLeft;我在这里搜索过,发现了许多用于Java或HTML的东西,但没有用于C#。 有任何想法吗?
谢谢!
I have a button on a C# Windows Form form, and want to show an image and some text, side by side, and centered on the button. I tried aligning the image to the left and the text to the right, and I'm getting this (the periods are spaces):
|[IMAGE}.................Text|
But I want this:
|........[IMAGE] Text........|
My code looks like this:
btnChangeStatus.Text = "Change status to SUPPRESSED"; btnChangeStatus.TextAlign = ContentAlignment.MiddleRight; btnChangeStatus.Image=Image.FromFile(@"J:\nomail.gif"); btnChangeStatus.ImageAlign = ContentAlignment.MiddleLeft;I've searched here, and found lots of stuff for Java or HTML, but nothing for C#. Any ideas?
Thanks!
最满意答案
将TextImageRelation设置为TextImageRelation.ImageBeforeText :
btnChangeStatus.TextImageRelation = TextImageRelation.ImageBeforeText; btnChangeStatus.TextAlign = ContentAlignment.MiddleCenter; btnChangeStatus.ImageAlign = ContentAlignment.MiddleCenter;指定图像在控件文本之前水平显示。
更新:你是对的,虽然听起来这应该做你想要的,它仍然有点左边。 我尝试了一下并使用
btnChangeStatus.TextImageRelation = TextImageRelation.ImageBeforeText; btnChangeStatus.TextAlign = ContentAlignment.MiddleRight; // <- right here btnChangeStatus.ImageAlign = ContentAlignment.MiddleCenter;导致了期望的结果,但我不知道为什么按钮表现得那样。
Set TextImageRelation to TextImageRelation.ImageBeforeText:
btnChangeStatus.TextImageRelation = TextImageRelation.ImageBeforeText; btnChangeStatus.TextAlign = ContentAlignment.MiddleCenter; btnChangeStatus.ImageAlign = ContentAlignment.MiddleCenter;Specifies that the image is displayed horizontally before the text of a control.
UPDATE: You are right, though it sounds like this should do what you want, it's still a little to the left. I tried around a little and using
btnChangeStatus.TextImageRelation = TextImageRelation.ImageBeforeText; btnChangeStatus.TextAlign = ContentAlignment.MiddleRight; // <- right here btnChangeStatus.ImageAlign = ContentAlignment.MiddleCenter;leads to the desired result, but I can't tell why the button behaves like that.
更多推荐
发布评论