Rounded Userform

Userform VBA yang dijalankan pada Windows 10 Kebawah akan menampilkan Userform berbentuk kotak.

Pada tutorial kali ini, saya akan menambahkan Windows API untuk membuat ujung tepi userform menjadi melengkung (Rounded)

Tambahkan script dibawah ini kedalam Module

#If Win64 And VBA7 Then   '64bit
Private Declare PtrSafe Function CreateRoundRectRgn Lib "gdi32.dll" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare PtrSafe Function SetWindowRgn Lib "user32.dll" _
     (ByVal Hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

#Else                      '32bit
Private Declare Function CreateRoundRectRgn Lib "gdi32.dll" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32.dll" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If


Public Sub BuatRound(xCaption)
Dim Hwnd As Long
Hwnd = FindWindow("ThunderDframe", xCaption)

SetWindowRgn Hwnd, CreateRoundRectRgn(10, 32, 460, 370, 20, 20), True
End Sub

Untuk membuat sebuh userform menjadi melengkung, tambahkan script berikut ini kedalam Userform_Initialize

Private Sub UserForm_Initialize()
BuatRound Me.Caption
End Sub

Ini tampilan sebelum ditambahkan Windows API Rounder Userform

Dan Berikut ini setelah ditambahkan Windows API Rounder Userform

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat WhatsApp
WhatsApp