在c#按钮上设置文本和图像

时间:2022-09-13 09:36:18

I have a WinForms application. In the Main form I have some buttons and I want to add an image beside the text.

我有一个WinForms应用程序。在主窗体中,我有一些按钮,我想在文本旁边添加一个图像。

I set the background Image property to the image I want and on the FormLoad event I set the image relation like that:

我将背景Image属性设置为我想要的图像,并在FormLoad事件上设置图像关系,如下所示:

button1.TextImageRelation = TextImageRelation.ImageBeforeText;

so i was expecting to get something like a "list" when on the left side there is an image and on the right side there is a text.

所以我希望得到类似“列表”的东西,当在左侧有一个图像,在右侧有一个文本。

but all i'm getting now is the text on the center of the button and multiplicity of the image vertically and horizontally

但我现在得到的只是按钮中心的文字和垂直和水平图像的多样性

3 个解决方案

#1


3  

You should use Image property of the button, not the BackgroundImage. The TextImageRelation works with the Image property.

您应该使用按钮的Image属性,而不是BackgroundImage。 TextImageRelation与Image属性一起使用。

This is an incorrect usage of BackgroundImage.

这是BackgroundImage的错误用法。

#2


0  

Ok I solved it by setting the BackgroundImageLayout to None

好的我通过将BackgroundImageLayout设置为None来解决它

#3


0  

Do nothing with the FormLoad event. Just click the button you want to change image and text of and press F4, that will bring the properties window. find for text and set it to nothing i.e delete anything you find in the text. for image you need to find for image in properties window and then brouse your desired image. that's all

FormLoad事件不执行任何操作。只需单击要更改图像和文本的按钮,然后按F4,即可显示属性窗口。查找文本并将其设置为空,即删除在文本中找到的任何内容。对于图像,您需要在属性窗口中找到图像,然后激发您想要的图像。就这样

#1


3  

You should use Image property of the button, not the BackgroundImage. The TextImageRelation works with the Image property.

您应该使用按钮的Image属性,而不是BackgroundImage。 TextImageRelation与Image属性一起使用。

This is an incorrect usage of BackgroundImage.

这是BackgroundImage的错误用法。

#2


0  

Ok I solved it by setting the BackgroundImageLayout to None

好的我通过将BackgroundImageLayout设置为None来解决它

#3


0  

Do nothing with the FormLoad event. Just click the button you want to change image and text of and press F4, that will bring the properties window. find for text and set it to nothing i.e delete anything you find in the text. for image you need to find for image in properties window and then brouse your desired image. that's all

FormLoad事件不执行任何操作。只需单击要更改图像和文本的按钮,然后按F4,即可显示属性窗口。查找文本并将其设置为空,即删除在文本中找到的任何内容。对于图像,您需要在属性窗口中找到图像,然后激发您想要的图像。就这样