[Học phần mềm] AutoPlay 12 Mở file trong máy tính hoặc trong Listbox
- Thứ hai - 15/03/2021 14:48
- In ra
- Đóng cửa sổ này
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…
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
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…
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:
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
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 – Một số ví dụ
A./ Mở file trên máy tính
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:
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
- Ví dụ sau khi chọn 1 số files có kết quả như sau:
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:
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