Mengubah Warna Text Msgbox

Mengubah warna pada tampilan Msgbox yang asalnya hitam menjadi warna apapun dengan bantuan Windows API

Option Explicit

'-----------------------------------------
' Sctipt VBA    : Msgbox Text Color
' Author        : https://vba.co.id
'                 Situs belajar VBA No.1
'                 di Indonesia
'-----------------------------------------

#If Win64 Then
    Private Declare PtrSafe Function GetSysColor Lib "user32"(ByVal nIndex As Long) As Long
    Private Declare PtrSafe Function SetSysColors Lib "user32" _
        (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long
#Else
    Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
    Private Declare Function SetSysColors Lib "user32" _
        (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long
#End If

Private Const COLOR_WINDOWTEXT As Long = 8
Private Const CHANGE_INDEX As Long = 1

Public Sub RunMe()
   Dim defaultColour As Long

   'simpan warna default Windows
   defaultColour = GetSysColor(COLOR_WINDOWTEXT)

   'Ubah warna ke merah dengan RGB
   SetSysColors CHANGE_INDEX, COLOR_WINDOWTEXT, RGB(51, 204, 204)
   MsgBox "Incorrect", vbCritical + vbYesNo, "Your result is..."

   'Ubah warna ke hijau dengan Enum
   SetSysColors CHANGE_INDEX, COLOR_WINDOWTEXT, vbGreen
   MsgBox "Correct", vbCritical + vbYesNo, "Your result is..."

   'Kembalikan lagi warna asal
   SetSysColors CHANGE_INDEX, COLOR_WINDOWTEXT, defaultColour

End Sub
List Tutorial
Apa yang sedang kamu cari?

Temukan beberapa kata kunci yang diinginkan.

Search