vb.net 在按钮中定位图像和文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16745511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Positioning Image and Text in a button
提问by Vishal
I have a Button on my Form. I want to have an image on the left and text on the right like :
我的表单上有一个按钮。我想在左边有一个图像,在右边有一个文本,比如:
Image Text
Image Text
But the problem is that image is not stretched here. I mean it does not fit the button.
但问题是图像没有在这里拉伸。我的意思是它不适合按钮。
So I tried to set the BackGroundImage
Property instead of Image
Property.
所以我试图设置BackGroundImage
属性而不是Image
属性。
Now I get the Image stretched. But I cant get the proper Format. I mean now I cant get Image on the left and Text on the right.
现在我得到了拉伸图像。但我无法获得正确的格式。我的意思是现在我无法在左侧获得图像而在右侧获得文本。
Is there any other control which I can use instead of button to Overcome this problem?
有没有其他控件可以代替按钮来解决这个问题?
采纳答案by tinstaafl
I don't think using stretch will in any case. How is it supposed to determine the border to stretch to? With the imagealign set middleleft and the textalign set middleright I was able to make this button, it's 82X48. The image I used is 52X39. I used paint to resize the image.
我认为无论如何都不会使用拉伸。它应该如何确定要延伸到的边界?使用 imagealign 设置 middleleft 和 textalign 设置 middleright 我能够制作这个按钮,它是 82X48。我使用的图像是 52X39。我用油漆来调整图像的大小。
回答by OneFineDay
The button has a TextImageRelation
property, set it to ImageBeforeText
. Set the Image
property with your image and there you go.
该按钮有一个TextImageRelation
属性,将其设置为ImageBeforeText
. Image
使用您的图像设置属性,然后就可以了。
回答by Some Guy
A simple method that may work out good is to put both an image and button inside a panel. This gives you the flexibility of text placement, image scaling and use anchor or dock options to size the controls with the panel and form. Not tested but sounds like it could work...
一个可能有效的简单方法是将图像和按钮都放在面板内。这为您提供了文本放置、图像缩放和使用锚点或停靠选项来调整面板和表单控件大小的灵活性。未经测试,但听起来它可以工作......
回答by matzone
If you used Button control .. and you want to add image to it
如果您使用 Button 控件 .. 并且您想向其中添加图像
Create New Button and do domething in it's properties
创建新按钮并在其属性中执行 domething
- Image: you can insert an image from anywhere (local or resource)
- ImageAlign: Set it to Middle Left
- TextAlign: Set it to Middle right
- 图像:您可以从任何地方(本地或资源)插入图像
- ImageAlign:将其设置为左中
- TextAlign:将其设置为右中
It tested on VB.NET 2005
它在 VB.NET 2005 上测试
回答by Daniel
To change a button's image size, you can use the image property . Your image will be resized to you specific dimension
要更改按钮的图像大小,您可以使用 image 属性。您的图像将调整为您的特定尺寸
Button2.Image = Image.FromFile("c:\image.jpg").GetThumbnailImage(20, 20, Nothing, IntPtr.Zero)