[Học phần mềm] AutoPlay 5 Xem hình trong máy tính
admin
2021-03-12T16:54:49+07:00
2021-03-12T16:54:49+07:00
http://linhhoitrithuc.com/hoc-phan-mem-sang-tao/hoc-phan-mem-autoplay-5-xem-hinh-trong-may-tinh-323.html
http://linhhoitrithuc.com/uploads/news/2021_03/image-20210312165327-1.png
Chia sẻ tri thức - Vững bước tương lai
http://linhhoitrithuc.com/uploads/logo_1.png
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));
endGhi 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