簡體   English   中英

在C#中設置按鈕的背景圖像

[英]Setting background image of button in C#

我想將圖像設置為Windows窗體按鈕的背景。

該圖像將添加到項目的資源中。

我該怎么做呢?

只需設置Button的BackgroundImage屬性即可。 一個例子:

button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Image));

在加載應用程序或進行設置時都可以使用它。

button.BackgroundImage = YourApplicationNamespace.Properties.Resources.yourImageHere;

在Visual Studio中,您可以執行以下操作:

  1. 轉到按鈕的屬性,然后單擊BackgroundImage項。
  2. 點擊“ ...”圖標。
  3. 點擊“本地資源”旁邊的單選按鈕。
  4. 點擊“導入”,然后選擇您想要的項目作為背景。
  5. 然后,點擊“確定”。

或者,您可以通過代碼執行以下操作:

button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Image));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM