[Học phần mềm] AutoPlay 5 Xem hình trong máy tính

400
5./ Xem hình trong máy tính
< Back – Một số ví dụ
Tạo Project xem hình ảnh trong máy tính với 2 Buttons, Button1 dùng để chọn thư mục có hình (.png và .jpg) và đưa vào ListBox, Button2 xem hình được chọn trong ListBox, ví dụ trên Page1 ta thiết kế như sau:
  • Tạo 2 xButton (nhấn Object > xButton), mở Properties của từng Button và đặt mục Text (Button Label) của xButton1 là Load, xButton2 là Open
  • Tạo 1 ListBox (Ctrl + Shift + 4), mở Properties > Settings và bỏ hết các Item
  • Tạo 1 Image (Ctrl + 4), chọn 1 hình
  • Mở Properties của xButton1 > Script > On Click, nhập:
–Disable listbox Updating
ListBox.SetUpdate(“ListBox1”, false);

–Get the desired folder to browse
folder = Dialog.FolderBrowse(“Open Folder”, “C:”);

–populate tables with all the .jpg and .png files
file_jpg = File.Find(folder, “*.jpg”, false, false, nil);
file_png = File.Find(folder, “*.png”, false, false, nil);

images = {file_jpg, file_png};
–do the following for each file:
for k in pairs(images) do –loops through the different image types
    for j,file_path in pairs(images[k]) do –loops through each image file
        –add the item to the listbox, with the name visible and path as data
        ListBox.AddItem(“ListBox1”, String.SplitPath(file_path).Filename, file_path);
    end
end

–Allow the listbox to display the updated content
ListBox.SetUpdate(“ListBox1”, true);
  • Mở Properties của xButton2 > Script > On Click, nhập:
selected = ListBox.GetSelected(“ListBox1”);
for j,k in pairs(selected) do
    Image.Load(“Image1”, ListBox.GetItemData(“ListBox1”, k));
end

Ghi chú:
  • Khi chạy chương trình, nếu không chọn hình mà nhấn Open thì sẽ hiện thông báo lỗi
  • Ta sửa lại On Click của xButton2 như sau (nil = nothing):
selected = ListBox.GetSelected(“ListBox1”);
if (selected ~= nil)
then
    for j,k in pairs(selected) do
        Image.Load(“Image1”, ListBox.GetItemData(“ListBox1”, k));
    end

else
    Dialog.Message(“Hello”, “Select music first!!!”)
end


 

THÔNG TIN GÓP Ý
        Quý thầy cô hoặc bạn đọc muốn đóng góp tài liệu, vui lòng gửi về:
    Fanpage: https://www.facebook.com/linhhoitrithuc (Chia sẻ tài nguyên miễn phí)
    Email: linhhoitrithuc@gmail.com  
Thống kê truy cập
  • Đang truy cập5
  • Hôm nay551
  • Tháng hiện tại10,373
  • Tổng lượt truy cập75,164
GIÁO ÁN THEO CHỦ ĐỀ
ĐỀ THI HK 2 TIỂU HỌC
giáo án theo công văn 5512
facebook
Đăng nhập
Hãy đăng nhập thành viên để trải nghiệm đầy đủ các tiện ích trên site
Bạn đã không sử dụng Site, Bấm vào đây để duy trì trạng thái đăng nhập. Thời gian chờ: 60 giây