Hướng dẫn hàm MSGBOXParams hiển thị ảnh tùy ý, màu, progress, unicode
Hướng dẫn hàm #MSGBOXParams hiển thị ảnh tùy ý, màu, progress, unicode.
+ Hướng dẫn nhúng ảnh vào Excel với control #BSImageList trong #BSAC, từ đây các control , hàm có thể hiển thị ảnh. File Excel mang sang máy khác không phải mang theo bộ file ảnh nữa. Tính năng này có từ BSAC v3.0.0.1, Add-in A-Tools v9.4.0.1.
Bạn thực hiện từng bước như sau:
Bước 1: chèn control BSImageList lên Worksheet hoặc lên Userform
Bước 2: Nạp ảnh vào BSImageList
Chọn BSImagelist, nhấp chuột phải chọn Properties.
(BSImageList lưu ảnh và có ImageIndex dùng khai báo trong các control: BSListView, BSTreeView, BSListBox, BSComboBox(x), BSButton, BSButtonEx,... để hiển thị ảnh/icon ).
Bước 3: Viết code để hiển thị MsgBox unicode hiển thị ảnh/icon, màu sắc, và progress
Sub MsgBoxParams_Icon()
Dim pr As TBSMsgBoxParams
'pr.Icon = ExtractIcon(Application.HinstancePtr, GetSysDir & "\shell32.dll", 220)
pr.Icon = Sheet2.BSImageList1.ListImages(1).HIcon
pr.BackColor = RGB(200, 10, 10)
pr.ForeColor = vbYellow
Dim x, s
s = "MsgBoxParams thay thÕ MsgBox ®Ó lµm ®îc nhiÒu viÖc:"
s = s & Chr(13) & "- HiÓn thÞ chuçi Unicode"
s = s & Chr(13) & "- Thay ®æi mµu nÒn, ch÷"
s = s & Chr(13) & "- HiÓn thÞ thanh Progress ®Ó ch¹y thêi gian."
s = s & Chr(13) & "- Thay ®æi Icon"
x = MsgBoxParams(s, VbMsgBoxStyle.vbInformation + VbMsgBoxStyle.vbYesNoCancel, "Tïy biÕn víi MsgBox b»ng MsgBoxParams", pr)
DestroyIcon pr.Icon 'free memory!
End Sub
|
Bước 4: Chạy macro, kết quả bạn nhận được như hình dưới đây
Download mã nguồn bạn thấy tôi đã viết ví dụ hiển thị thanh progress bar trong hàm MsgBox, có timer chạy lùi dần.
Hiển thị progress trong MsgBox
Sub MsgBoxParams_Progress()
Dim pr As TBSMsgBoxParams
'pr.Icon = ExtractIcon(Application.HinstancePtr, GetSysDir & "\shell32.dll", 220)
pr.Icon = Sheet2.BSImageList1.ListImages(0).HIcon
pr.BackColor = RGB(200, 10, 10)
pr.ForeColor = vbYellow
pr.TimerStruct.bAddProgress = True
pr.TimerStruct.nDuration = 30 ' seconds
pr.TimerStruct.nTimerCountDown = 0
pr.TimerStruct.bStopProgress = False
pr.TimerStruct.nInterval = 1000 ' 1 second
pr.TimerStruct.nExpireButtonClick_ID = ID_YES
pr.TimerStruct.nDisplayOnButton_ID = ID_CANCEL
Dim x, s
s = "T«i sÏ híng dÉn c¸c b¹n tïy biÕn hµm MessageBox víi hµm MsgBoxParams cña BSAC trong %d gi©y n÷a."
s = s & Chr(13) & "- HiÓn thÞ chuçi Unicode"
s = s & Chr(13) & "- Thay ®æi mµu nÒn, ch÷"
s = s & Chr(13) & "- HiÓn thÞ thanh Progress ®Ó ch¹y thêi gian."
s = s & Chr(13) & "- Thay ®æi Icon"
x = MsgBoxParams(s, VbMsgBoxStyle.vbInformation + VbMsgBoxStyle.vbYesNoCancel, "Tïy biÕn víi MsgBox", pr)
MsgBoxW x, vbInformation, "MsgBoxParams"
End Sub
|