[英]Resize an image in a button C# (not background image)
我在按鈕中插入了一個圖像,但它不是背景圖像。 所以,我想調整我想要的圖像大小,例如Height=30, Width=20
或有時Height=50, Width=50
。 有些人告訴我,如果將按鈕中的圖像作為背景圖像插入,則無法調整按鈕中的圖像大小。但是,如果我堅持要調整圖像大小,則可能嗎? 我不相信沒有人能做到。
這是一個windows窗體應用程序嗎? 如果我不明白這個問題,請原諒我,但如果您使用的是圖片框,您應該能夠從“屬性”菜單調整圖像大小。 右鍵單擊您插入的圖像,選擇屬性,應該有一個大小字段。
我假設您要調整按鈕內顯示的圖像大小。 您可以在 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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.