c#按钮上的图像和文本是否居中? [英] c# Image and text on a button, centered in the button?

查看:65
本文介绍了c#按钮上的图像和文本是否居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#Windows窗体表单上有一个按钮,并且想要显示图像和一些文本,并排并居中于该按钮上.我尝试将图像左对齐,文本右对齐,然后得到这个(句点是空格):

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|

但是我想要这个:

| ........ [IMAGE]文本........ |

|........[IMAGE] Text........|

我的代码如下:

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've searched here, and found lots of stuff for Java or HTML, but nothing for C#. Any ideas?

谢谢!

推荐答案

设置 TextImageRelation

指定在控件文本之前水平显示图像.

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.

这篇关于c#按钮上的图像和文本是否居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆