【发布时间】:2017-02-15 12:05:49
【问题描述】:
我在按钮中插入了一张图片,但它不是背景图片。所以,我想调整我想要的图像大小,例如Height=30, Width=20 或有时Height=50, Width=50。有人告诉我,如果我将按钮中的图像插入为背景图像,则无法调整其大小。但是,如果我坚持要调整图像的大小,这可能吗?我不相信没有人能做到。
【问题讨论】:
标签: c# image button controls imagebutton
我在按钮中插入了一张图片,但它不是背景图片。所以,我想调整我想要的图像大小,例如Height=30, Width=20 或有时Height=50, Width=50。有人告诉我,如果我将按钮中的图像插入为背景图像,则无法调整其大小。但是,如果我坚持要调整图像的大小,这可能吗?我不相信没有人能做到。
【问题讨论】:
标签: c# image button controls imagebutton
这是一个 Windows 窗体应用程序吗?如果我不理解这个问题,请原谅我,但如果您使用的是 PictureBox,您应该能够从“属性”菜单调整图像的大小。右键单击您插入的图像,选择属性,应该有一个尺寸字段。
【讨论】:
我假设您要调整按钮内的图像大小。您可以在 Designer File 中尝试这样的操作:
//
// ButtonName
//
this.ButtonName.AutoSize = false;
Image image = new Bitmap(customWidth,customHeight);
using (Graphics g = Graphics.FromImage(image )) {
g.DrawImage(FileLocation, 0, 0, customWidth, customHeight);
}
this.ButtonName.Image = image;
这将有助于按钮调整大小,但如果增加太多,图片将不清晰。
【讨论】:
Button.Resize += Button_Resize;
private void Button_Resize(object sender, EventArgs e)
{
Button button = (Button)sender;
Image resize = new Bitmap(button.Image,new Size(button.Image.Width, (button.Height - 13))); button.Image = resize;
}
【讨论】: