c#按钮中的图像和文字,按钮中心?(c# Image and text on a button, centered in the button?)

编程入门 行业动态 更新时间:2024-10-17 02:51:51
c#按钮中的图像和文字,按钮中心?(c# Image and text on a button, centered in the button?)

我在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.

更多推荐

本文发布于:2023-07-16 12:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   图像   文字   中心   button

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!