Board logo

標題: 如何在自定表單中開啟JPG檔案 [打印本頁]

作者: hbjang    時間: 2012-5-11 21:59     標題: 如何在自定表單中開啟JPG檔案

各位大大,
我在自訂表單中建立一個CommandButton,希望按下CommandButton後,能開啟固定路徑中的JPG檔案,請問該用哪一個指令或函式?謝謝
作者: oobird    時間: 2012-5-12 10:19

請說清楚固定路徑中的JPG檔案是要直接開啟還是引用到表單中?
作者: icestormer    時間: 2012-5-12 10:21

回復 1# hbjang


   不知你的做法是不是跟我做的一樣

我的是這樣
1:表單上有一個  Image1 (用來顯示JPG檔的圖像用)
2:在commandbutton 內寫上

Private Sub CommandButton4_Click()
  mypic = "C:\Users\user\Desktop\XXX.jpg" '原始圖像路徑及檔名 XXX是圖像檔名
       Image1.Picture = LoadPicture(mypic) '載入原始設定圖像檔
end sub
作者: oobird    時間: 2012-5-12 10:29

若你只是要打開圖檔用Shell指令最容易
Shell "cmd /c start d:\splash.jpg"
作者: hbjang    時間: 2012-5-12 18:59

解決了,本來我只想要開啟檔案,可是發現icestormer 大的方法更好,所以就改了方式,謝謝
我程式如下:
Private Sub CommandButton6_Click()

If UserForm1.ComboBox3.Value <> "" Then
mypic = "C:\Documents and Settings\Administrator\桌面\利達型錄\" & ComboBox1.Value & "\" & ComboBox2.Value & "\" & ComboBox3.Value & ".jpg"
UserForm3.Image1.Picture = LoadPicture(mypic)
UserForm3.Show
Else
MsgBox "請選擇產品!!"
End If

End Sub
作者: icestormer    時間: 2012-5-12 20:05

回復 5# hbjang


  很高興有幫助到你.不過別叫我大大..我也是VBA新手一枚..




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)