[Học phần mềm] AutoPlay 12 Mở file trong máy tính hoặc trong Listbox
admin
2021-03-15T14:49:55+07:00
2021-03-15T14:49:55+07:00
http://linhhoitrithuc.com/hoc-phan-mem-sang-tao/hoc-phan-mem-autoplay-12-mo-file-trong-may-tinh-hoac-trong-listbox-330.html
http://linhhoitrithuc.com/uploads/news/2021_03/image-20210315144852-2.png
Chia sẻ tri thức - Vững bước tương lai
http://linhhoitrithuc.com/uploads/logo_1.png
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… - 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
endB./ Mở file trong ListboxNhư 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:
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