【问题标题】:Is it possible to change the background image of a button when you click it? C# [closed]单击按钮时是否可以更改按钮的背景图像? C# [关闭]
【发布时间】:2013-10-22 06:24:52
【问题描述】:

是否可以在单击按钮时更改按钮的背景图像?我在 Windows 窗体应用程序上使用 C#。

【问题讨论】:

  • 是的,你试过搜索吗?
  • 请先使用谷歌,你会发现大量相关信息..
  • 在按钮事件中寻找,我认为使用 onclick 和 onrelease 事件可以实现,如果不是?只需创建一个新的自定义按钮。

标签: c# winforms button


【解决方案1】:

是的,这是可能的。只需在其单击事件上设置按钮的BackgroundImage 属性即可。

【讨论】:

  • 非常感谢!但是按钮上的图像没有被拉伸。你知道如何拉伸按钮上的图像吗?提前致谢。
  • 花一些时间阅读对象的属性等,更多细节请使用 find API 的 intellisens。 BackgroundImageLayout 是目前要查找的属性..
【解决方案2】:

试试这个,

button1.BackgroundImage = Image.FromFile("ImageFilepath");
button1.BackgroundImageLayout = ImageLayout.Stretch;

【讨论】:

    【解决方案3】:
    CSS3 的

    background-size 属性应该适合您,即 背景尺寸:覆盖背景尺寸:100%

    【讨论】:

    • 它是 Windows 窗体应用程序。不是网络应用程序。
    猜你喜欢
    • 2011-12-14
    • 1970-01-01
    • 2017-03-07
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    相关资源
    最近更新 更多