AutoPlay 12 Mở file trong máy tính hoặc trong Listbox

12./ Mở file trong máy tính hoặc trong Listbox

< Back – Một số ví dụ

A./ Mở file trên máy tính

autoplay_vd12c

Tạo nút nhấn mở Windows Explorer để chọn và mở file với các chương trình trong máy tính như file văn bản txt, doc, file hình ảnh jpg, png… file video, flash…

  • Ctrl + 1 tạo Button1
  • Nhấn phải vào Button1 > Properties > Script > On Click, nhập:

— Present the user with a file browse dialog (with multiple select set to true)
tFiles = Dialog.FileBrowse(true, “Multiple Select”, “”, “All Files(*.*)|*.*|”, “”, “”, true, true);
— Ensure that tFiles contains something
if tFiles then
   — Check if the user pressed “Cancel”
   if tFiles[1] == “CANCEL” then
      — The user pressed cancel, do nothing
   else
      — The user did not press cancel, traverse the table of files.
      for nIndex, sFile in pairs(tFiles) do
         — Open file with the default program.
         File.Open(sFile, “”, SW_SHOWNORMAL);
      end
   end
end

B./ Mở file trong Listbox

Như phần trên, nhưng các files được liệt kê sẳn trong Listbox:

  • Tạo 1 Listbox và 1 Button
  • Nhấn phải vào Listbox1 > Properties
  • Nhấn Item Text đặt tên
  • Nhấn phải vào ô dưới Item Data > Insert File Reference > chọn file

autoplay_vd12

  • Ví dụ sau khi chọn 1 số files có kết quả như sau:

autoPlay_vd12b.png

Các file trong Listbox sẽ tự động lưu vào các thư mục tương ứng trong Project, nhấn Project > File Layout để kiểm tra

  • Nhấn phải vào Button1 > Properties > Script > On Click, nhập:

selected = ListBox.GetSelected(“ListBox1”);
if (selected ~= nil) then
    file = ListBox.GetItemData(“ListBox1”, selected[1]);
    File.Open(file, “”, SW_SHOWNORMAL)
else
    Dialog.Message(“Hello”, “Select item in Listbox first”)
end

< Back

Bình luận về bài viết này