iT邦幫忙

1

Day 26視窗應用程式進階控制多媒體與時間控制:PictureBox(圖片框) & Timer(計時器)

c#
  • 分享至 

  • xImage
  •  

PictureBox(圖片框)
1.什麼是PictureBox
PictureBox是C# Windows Form應用程式中用來 顯示圖片 的控制項
它可以用來顯示:

  • 靜態圖片(例如:Logo、背景、角色)
  • 動態圖片(搭配 Timer 做動畫效果)
  • 使用者上傳的圖片(搭配 OpenFileDialog)**

2.常見屬性(Properties)
https://ithelp.ithome.com.tw/upload/images/20251010/201789257xhI7TSg3C.png

3.SizeMode屬性說明
https://ithelp.ithome.com.tw/upload/images/20251010/20178925uWhv9HUNne.png

Timer(計時器)
1.什麼是Timer
Timer是一個能夠在固定時間間隔下自動執行事件的控制項
簡單來說,它就像一個「鬧鐘」,每隔幾毫秒就會幫你「觸發一次程式」
常見用途:

  • 顯示時間(數位時鐘)
  • 動畫或圖片自動切換
  • 倒數計時
  • 自動偵測或更新資料

2.常見屬性(Properties)
https://ithelp.ithome.com.tw/upload/images/20251010/20178925A0ff6qGAtZ.png

PictureBox & Timer綜合範例
控制項
https://ithelp.ithome.com.tw/upload/images/20251010/20178925ht7EFAVsC2.png

加入圖片,按選擇影像,選擇本機資源按匯入,最後按確定
https://ithelp.ithome.com.tw/upload/images/20251010/20178925PG4t5ecw4o.png
https://ithelp.ithome.com.tw/upload/images/20251010/20178925R4ulaXG6RP.png
https://ithelp.ithome.com.tw/upload/images/20251010/20178925auuG6VYKTo.png

設定圖片大小,在屬性找到SizeMode設定
https://ithelp.ithome.com.tw/upload/images/20251010/201789252hjq6aSHdA.png
https://ithelp.ithome.com.tw/upload/images/20251010/20178925RIia8rk1SN.png

設定timer啟動,在屬性找到Enabled選擇True
https://ithelp.ithome.com.tw/upload/images/20251010/20178925Uq3RtM65NR.png

Interval屬性是設定每幾秒啟動一次,100=0.1秒
https://ithelp.ithome.com.tw/upload/images/20251010/20178925OsqvNwDS0X.png

程式碼
https://ithelp.ithome.com.tw/upload/images/20251010/20178925CNTCnJNAQf.png

執行後圖片會隨著時間移動
https://ithelp.ithome.com.tw/upload/images/20251010/20178925vlKi6mzwZV.png
https://ithelp.ithome.com.tw/upload/images/20251010/20178925pOUA4tKION.png


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言