【问题标题】:Resize an image in a button C# (not background image)调整按钮 C# 中的图像大小(不是背景图像)
【发布时间】:2017-02-15 12:05:49
【问题描述】:

我在按钮中插入了一张图片,但它不是背景图片。所以,我想调整我想要的图像大小,例如Height=30, Width=20 或有时Height=50, Width=50。有人告诉我,如果我将按钮中的图像插入为背景图像,则无法调整其大小。但是,如果我坚持要调整图像的大小,这可能吗?我不相信没有人能做到。

【问题讨论】:

    标签: c# image button controls imagebutton


    【解决方案1】:

    这是一个 Windows 窗体应用程序吗?如果我不理解这个问题,请原谅我,但如果您使用的是 PictureBox,您应该能够从“属性”菜单调整图像的大小。右键单击您插入的图像,选择属性,应该有一个尺寸字段。

    【讨论】:

    • 是的!这是一个窗口形式。如果我在按钮中导入了如何调整它的大小?如果我使用属性菜单,它属于按钮。
    • 你到底是怎么导入的?
    【解决方案2】:

    我假设您要调整按钮内的图像大小。您可以在 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;  
    

    这将有助于按钮调整大小,但如果增加太多,图片将不清晰。

    【讨论】:

      【解决方案3】:
      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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-04
        • 1970-01-01
        • 2015-12-19
        • 2015-04-30
        • 2012-04-10
        • 2019-10-03
        相关资源
        最近更新 更多